[热身题][hdoj_2072]单词数
2012-08-11 14:45
253 查看
// hdoj_2072 单词数 // 0MS 236K 695 B GCC #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加单词长度一直到>=len while(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; }
相关文章推荐
- HDOJ 2072 单词数 (set)
- HDOJ 2072 单词数【字符串】
- HDOJ_2072(单词数)
- HDOJ 2072 单词数
- Hdoj 2072 单词数
- hdoj-2072-单词数(结构体、大坑)
- HDoj-2072-单词数
- HDOJ 2072 单词数
- HDOJ2072 单词个数
- hdoj 2072 单词数
- hdoj 2072 单词数 (map)
- HDOJ2072(单词数)(strtok函数分解字符串)
- HDOJ-2072单词数(Trie树/MAP)
- 【hdoj】2072 单词数
- HDOJ2072 单词数
- hdoj 2072 单词数
- hdoj 2072 单词数 【字符串处理】
- ACM--HDOJ 2072--单词数--字符串--水
- HDOJ2072 单词数
- HDOJ.2072 单词数(map)