UVaOJ 414 - Machined Surfaces

//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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值