[热身题][hdoj_2072]单词数

来源:互联网 发布:手机解压缩密码软件 编辑:程序博客网 时间:2024/06/06 05:19
// hdoj_2072 单词数// 0MS236K695 BGCC#include <stdio.h>#include <string.h>char word[100000];char arr[100][100];     //arr用于存储以前出现过的单词int main(void){int len, pos, count;char temp[100];while(gets(word) && strcmp(word, "#") != 0){len = strlen(word);pos = 0;count = 0;// pos加单词长度一直到>=lenwhile(pos < len){sscanf(word + pos, "%s", temp); //把一个单词存入temp,空格忽略int i;for(i = 0; i < count; i ++)if(strcmp(arr[i], temp) == 0)//如果和以前存入的单词相同,则不计数break;if(i == count)strcpy(arr[count++], temp); //把temp存入arr,并计数器cnt加一/*用pos来记录下次读取的位置*/for(i = pos; word[i] == ' '; i++)//空格pos++;pos += strlen(temp) + 1;//单词}//判断是否全为空格int k, m = 0;for(k = 0; k < len; k ++)            if(word[k] == ' ')                m ++;        if(m == len)            printf("0\n");        else            printf("%d\n", count);}return 0;}


 

原创粉丝点击