码迷,mamicode.com
首页 > 其他好文 > 详细

刽子手游戏(UVa489)

时间:2018-07-03 18:09:27      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:turn   lin   php   round   index   i++   str   using   span   

  题目具体描述见: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 }

刽子手游戏(UVa489)

标签:turn   lin   php   round   index   i++   str   using   span   

原文地址:https://www.cnblogs.com/pgzhang/p/9259673.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!