ぼるじょあがC/C++の宿題を片づけますYO! 48代目
■ このスレッドは過去ログ倉庫に格納されています
0342デフォルトの名無しさん
2005/07/23(土) 23:21:37質問は受け付けません。
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define N 10
int main()
{
char *skip[] = {"a","the","by","for","in","on","of","to","with"};
char p[N][64] = {"this","is","a","pen","I","am","a","student","this","the"};
struct X { char *s;int cnt;} x[N];
int i, j, k, xend = 0;
for( i = 0; i < N; ++i)
{
for(k = 0; k < strlen(p[i]); ++k) p[i][k] = tolower(p[i][k]);
for(k = 0; k < sizeof(skip)/sizeof(*skip); ++k) if(0==strcmp(p[i],skip[k])) break;
if(k != sizeof(skip)/sizeof(*skip)) continue;
for(j = 0; j < xend; ++j)
if( 0 == strcmp(p[i], x[j].s) ) break;
if( j == xend ) {x[xend].s = p[i];x[xend].cnt = 1; ++xend;}
else ++x[j].cnt;
}
for(i = 0; i < xend; ++i)
printf("%s(%d), ", x[i].s, x[i].cnt);
return 0;
}
■ このスレッドは過去ログ倉庫に格納されています