刽子手游戏(UVa489)
题目具体描述见:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=430
C++11代码如下:
1 #include<iostream> 2 #include<string.h> 3 using namespace std; 4 char ans[100], test[100]; 5 6 int main() { 7 int rnd; 8 while ((cin>>rnd>>ans>>test)&&rnd!=-1) { 9 cout << "Round " << rnd << endl; 10 int chance = 7; 11 int left_ch = strlen(ans); 12 for (int i = 0; i < strlen(test); i++) { 13 bool bad = true; 14 for (int j = 0; j < strlen(ans); j++) { 15 if (ans[j] == test[i]) { 16 ans[j] = ' '; 17 left_ch--; 18 bad=false; 19 } 20 } 21 if (bad) --chance; 22 if (!(left_ch && chance)) break; 23 } 24 if (!left_ch) cout << "You win."<<endl; 25 else if (!chance) cout << "You lose."<<endl; 26 else cout << "You chickened out."<<endl; 27 } 28 return 0; 29 }