信使
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
64 位 IO 格式: %lld
空间限制:C/C++ 262144K,其他语言524288K
64 位 IO 格式: %lld
题目描述
通过给用户最多七个猜测来玩新游戏,以找出一个字母(发音:letter-el)。字母由五个字母(A-Z)组成,按特定顺序排列。每次猜测后,都会向用户提供有关其猜测正确性的反馈。反馈以五个字母的字符串形式提供,仅包含以下字母:X、Y 和 G。
X = 此位置的字母不出现在字母中
Y = 此位置的字母出现在字母中,但它不在正确的位置
G = 字母在这个位置是正确的(好)。
对于此问题,您将编写一个程序,该程序为提供的 letterle 生成最多七个猜测的反馈。
输入描述:
The first line of input contains a five character string of capital letters (A-Z) that are the letterle. The next seven lines contain guesses that the program must evaluate and generate feedback for the user.
输出描述:
Output consists of one or more lines. For each guess, if the guess is correct, the output line is WINNER and the program should not process any more input. If the guess is incorrect, and this is the seventh guess, the output line is “LOSER”. Otherwise, the output line is a five character string where each position has one of X, Y or G (as described above). First, any position that a letter is correct, should have a G. Then, any position where a letter is not in the letterle, should contain an X. The remaining positions should contain a Y indicating the letter is correct, but in the wrong position.
示例1
输出
复制XXXXX
XXXGX
XYGXX
XXXXG
WINNER
#include<bits/stdc++.h>
using namespace std;
int character[29];
string s,t;
int main(){
cin>>s;
for(int i=0;i<5;i++)
character[s[i]-'A']=1;
for(int i=1;i<=7;i++){
cin>>t;
if(s==t) return cout<<"WINNER",0;
if(i==7) return cout<<"LOSER",0;
for(int i=0;i<5;i++){
if(s[i]==t[i]) cout<<'G';
else if(character[t[i]-'A']) cout<<'Y';
else cout<<'X';
}
cout<<endl;
}
return 0;
}