数字猜想-Hunan University 2008 the 4th Programming Contest
来源:互联网 发布:澳洲旅游签证知乎 编辑:程序博客网 时间:2024/05/18 23:11
描述
数字猜想是一个电脑游戏。首先,电脑会选择四个不重复的数字,你要根据电脑的提示尽快地猜出这个数字。电脑给的提示形式是“#A#B”,其中“#”是0~4的数字。其中“#A”表示猜中了数字.和位置的数目,“#B”表示猜中数字的数目。比如,电脑选择的是1234,你猜的是6139,电脑给的提示是“1A2B”,因为数字“3”既猜中了数字,也猜对了位置,而数字“1”只猜中了数字,所以电脑给的提示就是“1A2B”。
现在,你仔细记录了你每次猜的数字和电脑的提示,你感觉应该可以猜对结果了。是的,生活中充满了智慧,不是吗?
输入
有多个测试序列。每个测试序列的第一行是一个单独的正整数N,表示猜想的次数,接下来的N行是N次猜想的记录,形式为:
#### #A#B
前面四个数字是猜想的数字,后面是电脑对猜想的提示。
输入N为0或者负整数表示输入结束,并且无须处理。
输出
对于每个测试序列,输出一行,给出电脑选定的数字,要求数字和位置都正确。你可以假设,每个测试序列都提供了足够的信息,让你可以猜出该数字。
样例输入
2
1234 2A4B
1243 0A4B
3
0732 3A3B
1526 0A0B
4567 0A2B
-1
1234 2A4B
1243 0A4B
3
0732 3A3B
1526 0A0B
4567 0A2B
-1
样例输出
2134
0734
0734
#include<iostream>#include<cstring>using namespace std;struct node{ char str[5]; int a,b;};node we[1000];int main(){ int a,b,c,d,n,i,j,t[100]; char ab[5],tem[5]; while(cin>>n) { if(n==-1)break; for(i=0;i<n;i++) { cin>>we[i].str>>tem; we[i].a=tem[0]-48; we[i].b=tem[2]-48; } for(a=0;a<10;a++) for(b=0;b<10;b++) for(c=0;c<10;c++) for(d=0;d<10;d++) { //cout<<"frawef"<<endl; //if(f==0)break; if(a!=b&&a!=c&&a!=d&&b!=c&&b!=d&&c!=d) { ab[0]=char(a+48); ab[1]=char(b+48); ab[2]=char(c+48); ab[3]=char(d+48); ab[4]='\0'; //cout<<c<<endl; memset(t,0,sizeof(t)); t[a]=t[b]=t[c]=t[d]=1; for(i=0;i<n;i++) { int s=0,x=0; for(j=0;j<4;j++) { if(t[we[i].str[j]-48])s++; if((we[i].str[j])==ab[j]){x++; } } if(s!=we[i].b||x!=we[i].a)break; } if(i==n) { cout<<ab<<endl; // f=0; } } } } return 0;}
0 0
- 数字猜想-Hunan University 2008 the 4th Programming Contest
- Hunan University 2008 the 4th Programming Contest - 11135 - The ones to remain
- The 2012 8th Hunan University Programming Contest 水题
- The 11-th Programming Contest of Hunan University -- Trailing Zeros of Factorials
- Hunan University 2009 the 5th Programming Contest - 11443- 8 numbers problem
- The 12th Zhejiang University Programming Contest
- The 14th Zhejiang University Programming Contest
- The 14th Zhejiang University Programming Contest
- [The 14th Zhejiang University Programming Contest]
- The 15th Zhejiang University Programming Contest
- The 15th Zhejiang University Programming Contest
- The 15th Zhejiang University Programming Contest
- The 15th Zhejiang University Programming Contest
- The 16th Zhejiang University Programming Contest-
- The 11th Zhejiang University Programming Contest / 解题报告 4.3
- The 11th Zhejiang University Programming Contest - C/ Chinese Zodiac
- The 11th Zhejiang University Programming Contest - G/ Gaussian Prime
- The 11th Zhejiang University Programming Contest C G J
- apache2+passenger遇到的问题总结:
- viewpage + fragment
- 在熟练使用2B铅笔前,请不要打开Axure
- onSaveInstanceState和onRestoreInstanceState触发的时机
- 一步步学习SPD2010--第七章节--使用BCS业务连接服务(4)--创建Office应用程序外部内容类型
- 数字猜想-Hunan University 2008 the 4th Programming Contest
- 关于cocos2d-html5 中使用重力感应于重力加速
- 一步步学习SPD2010--第七章节--使用BCS业务连接服务(5)--创建和管理外部列表
- Linux脚本发邮件中文乱码解决
- 一步步学习SPD2010--第七章节--使用BCS业务连接服务(6)--处理Office应用程序外部内容类型
- HashMap遍历
- json-lib利用注解屏蔽不需要的字段
- HttpClient对webserive测试
- 嵌入式 GCC或者G++编译优化选项(适合嵌入式的有限空间)