标签:应该 ref std ++ names lan 输出 pre tar
题目大意:
http://codevs.cn/problem/1084/
本道题目有两个坑:
1. 比赛双方的比分的差必须大于2,(按照实际的规则弄得,题目中没有说)
2.读入字符串的时候,E标志着字符串的结尾,但是也要读进字符串。例如:
WWWWWWWWWWWE(11个W,一个E):
程序的输出结果应该是:
11:0
0:0
而不应该只是:
11:0
代码:
#include <iostream> using namespace std; void f(string s,int n) { int i = 0, ww = 0, ll = 0; while(i < s.length()){ if(s[i] == ‘W‘){ ww++; } if(s[i] == ‘L‘){ ll++; } if(((ww >= n || ll >= n)&&((ll-ww >= 2) ||(ww-ll >= 2))) || i+1 == s.length()){ cout << ww << ":" << ll << endl; ww = 0;ll = 0; } i++; } } int main() { char ch; string s = ""; while(cin >> ch){ s += ch; if(ch == ‘E‘){ s += ‘E‘; break; } } if(s == "") { cout << "0:0" << endl; cout << endl; cout << "0:0" << endl; } f(s,11); cout << endl; f(s,21); return 0; }
标签:应该 ref std ++ names lan 输出 pre tar
原文地址:http://www.cnblogs.com/zyqBlog/p/7615614.html