C/C++の宿題片付けます 153代目at TECH
C/C++の宿題片付けます 153代目 - 暇つぶし2ch122:デフォルトの名無しさん
11/11/08 23:05:06.04
>>118
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct tag_wordlist_t{
char *word;
int count;
struct tag_wordlist_t *next;
}wordlist_t;
int main(void){
char a[]="バナナ リンゴ スイカ バナナ", *p, buf[100+1];
int n;
wordlist_t *first=NULL, *last=NULL, *list_new, *it;
for(p=a;sscanf(p, "%100s%n", buf, &n)>=1;p+=n){
for(it=first;it;it=it->next){
if(strcmp(it->word, buf)==0){
it->count++;
break;
}
}
if(it==NULL){
list_new=malloc(sizeof(wordlist_t));
list_new->word=strdup(buf);
list_new->count=1;
list_new->next=NULL;
if(last) last=last->next=list_new;
else first=last=list_new;
}
}
for(it=first;it;it=it->next) printf("%s %d\n", it->word, it->count);
return 0;
}


次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch