zoukankan      html  css  js  c++  java
  • UVA

    /*
      入门经典P80-81有题解,十分详细
      入门经典上有提醒,猜一个已经猜过的字母也算错...我英语理解能力不是太好,猜测应该是原题里的这句话"Each unique wrong guess only counts against the contestant once.",也许是表示每次错误的猜测都是单独起作用的?所以如果两次猜错都是同一个字母,那就错两次?
      
      总而言之,英文阅读能力还是要加强,不然连题目都读不懂 T^T
      
      另外发现,我用C++写的时候,DevC上居然报了一堆编译错,说left变量有问题,后来想了想,left应该算C++的关键字,因为IO流控制输入输出时,是有ios::left表示输入时左对齐的,所以就换成了rest
      
      务必谨慎!~就像之前遇到过的,round和clock也是C++有的函数,不要再用它们定义变量名了...越学越发现直接基础并不太扎实,加油加油,日进有功!
    */


    #include <iostream>
    #include <cstring>
    //#define debug
    using namespace std;
    const int maxn = 1005;
    
    int rest, chance, win, lose;
    char word[maxn], ans[maxn];
    
    void guess(char ch)
    {
    	bool flag = false;
    	int len = strlen(word);
    	for (int i = 0; i < len; i++)
    	if (word[i] == ch)
    	{
    		rest--; word[i] = ' '; flag = true;
    	}
    	if (!flag) chance--;
    	if (!chance) lose = 1;
    	if (!rest) win = 1;
    }
    
    int main()
    {
    	#ifdef debug
    	freopen("E:\in.txt", "r", stdin);
    	freopen("E:\out.txt", "w", stdout);
    	#endif	
    	int rnd;
    	while (cin >> rnd >> word >> ans && rnd != -1)
    	{
    		win = lose = 0;
    		chance = 7;
    		rest = strlen(word);
    		int len = strlen(ans);
    		
    		for (int i = 0; i < len; i++)
    		{
    			guess(ans[i]); //猜一个字母 
    			if (win || lose) break; //检查状态 
    		}
    		
    		//根据结果进行输出 
    		cout << "Round " << rnd << endl;
    		if (win) cout << "You win."; 
    		else if (lose) cout << "You lose.";
    		else cout << "You chickened out.";
    		cout << endl;
    	}	
    	#ifdef debug
    	fclose(stdin);
    	fclose(stdout);
    	#endif
    	return 0;
    }


  • 相关阅读:
    最优装载(二分答案)
    最小生成树
    hibernate映射实体类查询时数据库空字段赋值给实体类报错的问题
    'hibernate.dialect' must be set when no Connection avalable
    简单了解一下oracle中的显示游标和存储过程
    oracle中的预定异常和自定义异常
    PL/sql中如何声明变量,常量,控制语句及for,loop,while和顺序控制的使用
    简单了解,使用oracle中的索引,表分区
    oracle中序列,同义词的创建
    数据库权限管理
  • 原文地址:https://www.cnblogs.com/mofushaohua/p/7789534.html
Copyright © 2011-2022 走看看