Login
Immutable PageDiscussionInfoAttachments
Diff for "rei05/C言語"

MMA
Differences between revisions 9 and 10
Revision 9 as of 2012-05-09 01:04:47
Size: 898
Editor: rei05
Comment:
Revision 10 as of 2012-05-09 01:05:25
Size: 897
Editor: rei05
Comment:
Deletions are marked like this. Additions are marked like this.
Line 12: Line 12:
char ch,counter[256]={0}; char ch,counter[26]={0};

Help Me!

#include<stdio.h>

int main(){

int num,i,pri;
char ch,counter[26]={0};

while(scanf("%c",&ch)!=EOF){   //入力終了条件を\nからEOFに修正
  scanf("%c",&ch);
  if('a'<=ch&&ch<='z'){
    num=ch-'a';
    counter[num]++;
  }else if('A'<=ch&&ch<='Z'){
    num=ch-'A';
    counter[num]++;
  }
}

for(i=0;i<=25;i++){
  pri=counter[i];
  printf("%c : %d\n",i+'a',pri);
}

return(0);
}
  • counterをリセットしないと2回目以降の結果がバグると思いますよん-- alstamber 2012-05-08 22:09:37

  • すみません具体的にどこをどう直せば良いですか?問題文を見る限り動かすのは1回でいいと思うのですが。-- rei05 2012-05-09 01:00:33

rei05/C言語 (last edited 2012-07-16 17:50:37 by nomeaning)