|
Post by huangno1 on Feb 26, 2017 22:14:58 GMT -8
程式說明
請撰寫一個程式,程式首先會輸入一串「僅包含大寫英文字母」的字元。
接著,使用者每次輸入一個查詢的字元,程式會列印出該字元出現過幾次。
若輸入 @ 則程式結束。
執行範例:
Please input a string (including only A~Z)...>BBBB
>A
There are 0 'A' in your input.
>B
There are 4 'B' in your input.
>C
There are 0 'C' in your input.
>@
#include <stdio.h>
int main()
{
int count [ 26 ] = { 0 };
char input = getchar();
while (input != '\n')
{
count [ input - 'A' ] += 1 ;
input = getchar();
}
// key
printf(">");
scanf(" %c", &input);
while (input != '@')
{
printf ( "There are %d '%c' in your input.\n" , count [ input - 'A' ] , input ) ;
printf(">");
scanf(" %c", &input);
}
return 0;
}
|
|