UVaOJ 414 - Machined Surfaces
2014-05-05 23:22
204 查看
//1.最讨厌这种输出要求不明晰的题目,"round %d\n"该输出在输入两个字符串之前,还是输出结果之前! //2.第二个就是我自己的疏漏,详看代码 #include <stdio.h> #include <string.h> #include <ctype.h> int main() { int round = -1; int len = 0; int chs[26]; char buf[50]; memset(chs, 0, sizeof(chs)); memset(buf, '\0', sizeof(buf)); while (scanf("%d", &round) == 1 && round != -1) { getchar(); printf("Round %d\n", round); fgets(buf, sizeof(buf), stdin); char *tmp = buf; while (*tmp) { if (chs[tolower(*tmp) - 'a'] == 0) { chs[tolower(*tmp) - 'a'] = 1; ++len; } ++tmp; } memset(buf, '\0', sizeof(buf)); fgets(buf, sizeof(buf), stdin); tmp = buf; int n = 7; while (*tmp && n > 0) { if (chs[*tmp - 'a'] == 1) { chs[*tmp - 'a'] = 2; //原来上面我写=0就算了,后来才发现这样导致疏漏: //第一次输入答案中拥有的字符会先使其变0, //当再一次重复输入此字符时,就当成了答案中没有的字符, //导致重复--n了!结果自然错误 --len; } else if (chs[*tmp - 'a'] == 0) { chs[*tmp - 'a'] = -1; //开始我没写上面这句,导致了重复输入答案字符中没有的字符,导致重复--n了!结果自然错误 --n; } ++tmp; } if (len == 0) printf("You win.\n"); else if (n == 0) printf("You lose.\n"); else printf("You chickened out.\n"); memset(chs, 0, sizeof(chs)); memset(buf, '\0', sizeof(buf)); len = 0; } return 0; }
相关文章推荐
- UVAOJ 414 - Machined Surfaces
- UVaOJ 414 - Machined Surfaces
- UVaOJ 414 - Machined Surfaces
- uva414 Machined Surfaces
- UVA 414 - Machined Surfaces
- UVA414—— Machined Surfaces
- 414 - Machined Surfaces
- UVa 414 - Machined Surfaces
- UVA 414 - Machined Surfaces
- 414 - Machined Surfaces
- UVa - 414 - Machined Surfaces 题解
- UVA 414 - Machined Surfaces解题心得
- uva 414 - Machined Surfaces
- UVA 414 - Machined Surfaces
- UVA 414-Machined Surfaces
- 414 - Machined Surfaces
- 414 - Machined Surfaces
- UVA - 414 Machined Surfaces
- UVA - 414 Machined Surfaces
- uva414 - Machined Surfaces