C/C++の宿題を片付けます 96代目
■ このスレッドは過去ログ倉庫に格納されています
0744デフォルトの名無しさん
2007/10/05(金) 20:36:16Cの勉強がてら書いてみた.
#include <stdio.h>
#include <string.h>
#define itemof(array, index) (*(array+index))
#define MAXSTRLEN 15
#define SCANFORMAT(n) _SCANFORMAT(n)
#define _SCANFORMAT(n) "%"#n"s"
int main(void){
int i, strlentable[MAXSTRLEN];
char str[MAXSTRLEN+1];
for(i=0;i<MAXSTRLEN;i++)
itemof(strlentable, i-1)=0;
while(1){
scanf(SCANFORMAT(MAXSTRLEN), str);
if(strcmp(str,"*")==0)
break;
else{
int _strlen=strlen(str);
itemof(strlentable, _strlen-1)++;
}
}
for(i=0;i<MAXSTRLEN;i++)
printf("count of strlen==%d =%d\n", i, itemof(strlentable, i-1));
}
■ このスレッドは過去ログ倉庫に格納されています