C/C++の宿題を片付けます 80代目
■ このスレッドは過去ログ倉庫に格納されています
0587デフォルトの名無しさん
2007/01/08(月) 23:44:151番
「文字数」は印字可能な文字(SPより後)の個数という意味にとった。
#include <stdio.h>
#include <stdbool.h>
void main() {
int c, chars = 0, words = 0, sentences = 0;
bool sp = false;
while((c = getchar()) != EOF) {
switch(c) {
case '.':
case '?':
case '!':
sentences++;
case ',':
chars++;
case ' ':
if(!sp) words++, sp = true;
break;
default:
if(c > 0x20) chars++;
sp = false;
}
}
printf("%d %d %d\n", chars, words, sentences);
}
■ このスレッドは過去ログ倉庫に格納されています