376 条题解
-
26
Dinghow LV 6 @ 2017-04-15 15:21:58
#include<iostream> #include<cmath> using namespace std; char letter[100000]; void Output(int cap,int type) { int w = 0, l = 0; for (int i = 0; i < cap; i++) { if (letter[i] == 'W') w++; if (letter[i] == 'L') l++; if (((w == type||l==type)&&(abs(l-w)>=2))||((w>type||l>type)&&(abs(l-w)==2)) ){ cout << w << ':' << l; w = 0, l = 0; cout << endl; } } cout << w << ':' << l; } int main() { int i = 0; while ((letter[i] = getchar()) != EOF) { if (letter[i] == 'E') break; i++; } Output(i, 11); cout << endl<<endl; Output(i, 21); return 0; }
-
182017-03-01 16:39:38@
题目很简单,细节要考虑周到:
1.第一个点直接读入了一个‘E’;
2.最后一个点是在一次完整的计分并输出后————即此时比分为0:0,那么就要输出‘0:0’(题目中有提示;
3.刚刚上面有个括号补全;
4.为什么我按一下enter它自动给我加了一个‘4.’;
5.这个网站好强啊!
6.代码反正也没人读就不贴了! -
42021-04-21 19:24:45@
作为模拟的话乒乓球真是个很棒的题
这题我在2018年夏令营上机的时候见到过由于当时上的D班,本人太蔡了,所以看了看题目就放弃了=w=
现在回首当年冬令营,自己应该能做出来的,只不过畏难心理搞的鬼,看旁边的大佬 都在抠所以就没敢做...
这个故事告诉我:在编程生涯中,不要有畏难心理,实际上很多题目只要用心去理解,去转化题意,就会发现并不是你想象中的那么难。更不要在考试中东张西望看别的大佬做不做的出来,一定要自己尝试哦=w=(相信自己,哦哦哦哦哦)
哎呀呀跑题了
上面几段可以不看=w=都是废话
但是实际上这题并不是很难(虽然我刚刚AC就来写题解了),细节可能有很多,但是没卡到我太多awa。那么接下来开讲啦!
首先,这个输入就是一个坑(至少对我这样的蒟蒻来说是个坑)
题目是这么说的:“每个输入文件包含若干行字符串,字符串有大写的W、L和E组成。其中E表示比赛信息结束,程序应该忽略E之后的所有内容。”
划重点:若干行字符串
其实这里我就被坑到了TAT
相信很多小伙伴和我一样,看到输入数据以为就是一个字符串解决...
刚刚还想用字符串偷懒的我懵了...那么只能用字符数组来解决了吖=w=
输入就是这么输的:
#include<bits/stdc++.h> using namespace std; char ch,s[62510]//至于为什么是62510看说明提示; int a,b,emm//emm表示分数总数量(同时也是下标)a,b下文会讲; int main(){ while(cin>>ch){//一直输入 if(ch=='E')break;//如果是E就结束(防止E不是最后一个字符这一情况发生) else s[++emm]=ch;//存入字符数组中 } //awa }
另外说明一下,测试数据里E不一定是最后一个输入的字符,如果不判断,把E后面的数也存进去就炸了哟~
接下来就是**核心部分**啦!
核心部分坑更多,在此就不一一列举了=w=但是要说一下本题的最坑的就是比分一定要直到分差大于或者等于2(在不小于11或21的情况下)。。。
那么为此,我写了两个判断语句(先以11分制为例):
if(a==11&&a>b&&a-b>=2||b==11&&b>a&&b-a>=2)
这个是判断11分就赢的情况。a和b就是这个谁和那个谁的当局得分(下局清零的)
if(a>=11&&a>b&&a-b>=2||b>=11&&b>a&&b-a>=2)
这个嘛,就是判断高分超过11的情况啦=w=(是不是没有想象中那么复杂)
21分赛制就把判断语句中的11改成21就可以了吖
完整代码如下:
#include<bits/stdc++.h> using namespace std; char ch,s[62510]; int a,b,emm; int main(){ while(cin>>ch){ if(ch=='E')break; else s[++emm]=ch; } for(int i=1;i<=emm;i++){ if(s[i]=='W')a++; else if(s[i]=='L')b++; if(a==11&&a>b&&a-b>=2||b==11&&b>a&&b-a>=2){ cout<<a<<":"<<b<<endl; a=0; b=0; } else if(a>=11&&a>b&&a-b>=2||b>=11&&b>a&&b-a>=2){ cout<<a<<":"<<b<<endl; a=0; b=0; } } cout<<a<<":"<<b<<endl<<endl; a=0; b=0; for(int i=1;i<=emm;i++){ if(s[i]=='W')a++; else if(s[i]=='L')b++; if(a==21&&a>b&&a-b>=2||b==21&&b>a&&b-a>2){ cout<<a<<":"<<b<<endl; a=0; b=0; } else if(a>=21&&a>b&&a-b>=2||b>=21&&b>a&&b-a>=2){ cout<<a<<":"<<b<<endl; a=0; b=0; } } cout<<a<<":"<<b<<endl; return 0; } 然后就愉快地AC啦!
当然有小伙伴哪些细节不懂的欢迎来私信我哦~
(vijos就没有比我蔡的这么说岂不是找打)
我是麒麟吃稀饭
,如果你能看到这篇题解的话,那么它就是我的第二篇题解啦!喜欢的话别忘了顶一下哟,也欢迎你的点赞,评论,关注,素质三连(我一个蒟蒻写题解也不容易啊)
谢谢观看!
-
42018-02-09 21:15:42@
看了好久都没java的,来一波java版本的,要注意是若干行!
import java.util.Scanner; //交叉模拟 把比赛的情况模拟出来 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); StringBuilder sb = new StringBuilder(); String res, string; while(true) { string = in.nextLine(); if (string.contains("E")) { sb.append(string); break; } sb.append(string); } res = sb.toString(); in.close(); char[] ch = new char[res.length()]; ch = res.toCharArray(); getPoints(ch, 11); System.out.println(); getPoints(ch, 21); } private static void getPoints(char[] record, int point) { int me = 0; int you = 0; for (int i = 0; i < record.length; i ++) { if (record[i] == 'E') { System.out.println(me + ":" + you); break; } if (record[i] == 'W') { me ++; } if (record[i] == 'L') { you ++; } if (me >= point || you >= point) { if (Math.abs(me - you) >= 2) { System.out.println(me + ":" + you); me = 0; you = 0; } } } } }
-
42017-02-26 21:34:32@
#include <stdio.h>
#include <math.h>
char s[100000];
int main()
{
int i = 0,j,a=0,b=0;do{
scanf("%c",&s[i]);
}while(s[i++]!='E');for(j=0;j<i-1;j++)
{
if(s[j]=='W')
a++;
if(s[j]=='L')
b++;
if(s[j]=='\n')
continue;
if((a==11||b==11)&&abs(a-b)>=2)
{
printf("%d:%d\n",a,b);
a=0;
b=0;
}
if(a>=10&&b>=10)
{
while(abs(a-b)>=2)
{
printf("%d:%d\n",a,b);
a=0;
b=0;
}
}
}
printf("%d:%d\n",a,b);
a=0;
b=0;printf("\n");
for(j=0;j<i-1;j++)
{
if(s[j]=='W')
a++;
if(s[j]=='L')
b++;
if(s[j]=='\n')
continue;
if((a==21||b==21)&&abs(a-b)>=2)
{
printf("%d:%d\n",a,b);
a=0;
b=0;
}
if(a>=20&&b>=20)
{
while(abs(a-b)>=2)
{
printf("%d:%d\n",a,b);
a=0;
b=0;
}
}
}
printf("%d:%d",a,b);
return 0;
} -
12021-10-16 12:40:51@
C++暴力枚举法
(还好char设置够了)#include <iostream> #include <cmath> using namespace std; char a[100000]; int main() { int me = 0,you = 0,temp = 0; while(true) { temp++; cin >> a[temp]; if(a[temp] == 'W') { me++; } else if(a[temp] == 'L') { you++; } if((me == 11||you == 11) && abs(me - you) >= 2) { cout << me << ":" << you << endl; me = 0;you = 0; } else if((me >= 11 || you >= 11) && abs(me - you) == 2) { cout << me << ":" << you << endl; me = 0;you = 0; } if(a[temp] == 'E') { cout << me << ":" << you << endl << endl; me = 0;you = 0;temp = 0; break; } } while(true) { temp++; if(a[temp] == 'W') { me++; } else if(a[temp] == 'L') { you++; } if((me == 21||you == 21) && abs(me - you) >= 2) { cout << me << ":" << you << endl; me = 0;you = 0; } else if((me >= 21 || you >= 21) && abs(me - you) == 2) { cout << me << ":" << you << endl; me = 0;you = 0; } if(a[temp] == 'E') { cout << me << ":" << you << endl; me = 0;you = 0;temp = 0; break; } } return 0; }
快乐
-
12021-08-29 16:49:37@
#include <bits/stdc++.h> using namespace std; char ch,s[62510]; int a,b,emm; int main(){ while(cin>>ch){ if(ch=='E')break; else s[++emm]=ch; } for(int i=1;i<=emm;i++){ if(s[i]=='W')a++; else if(s[i]=='L')b++; if(a==11&&a>b&&a-b>=2||b==11&&b>a&&b-a>=2){ cout<<a<<":"<<b<<endl; a=0; b=0; } else if(a>=11&&a>b&&a-b>=2||b>=11&&b>a&&b-a>=2){ cout<<a<<":"<<b<<endl; a=0; b=0; } } cout<<a<<":"<<b<<endl<<endl; a=0; b=0; for(int i=1;i<=emm;i++){ if(s[i]=='W')a++; else if(s[i]=='L')b++; if(a==21&&a>b&&a-b>=2||b==21&&b>a&&b-a>2){ cout<<a<<":"<<b<<endl; a=0; b=0; } else if(a>=21&&a>b&&a-b>=2||b>=21&&b>a&&b-a>=2){ cout<<a<<":"<<b<<endl; a=0; b=0; } } cout<<a<<":"<<b<<endl; return 0; }
-
12021-07-17 15:56:01@
自动AC机直接过
-
12019-05-26 17:41:15@
#include<iostream> #include<cstdlib> #include<string> using namespace std; int main() { string s1,s2;//方便输入 while(getline(cin,s2))s1+=s2;//输入字符串 int i=0,a=0,b=0;//i是指针,a统计了赢的次数,b是输的次数 while(s1[i]!='E')//只要不是结束符,现在是判断11分制 { switch(s1[i])//switch判断s1[i] { case 'W':a++;break;//如果s1[i]是‘W’,累计到a里 case 'L':b++;break;//如果s1[i]是‘E’,累计到b里 } if((a>=11||b>=11)&&(abs(a-b)>=2))//是否到达条件,一盘有没有结束 { cout<<a<<":"<<b<<endl;//输出 a=0;b=0;//清零,下一盘 } i++;//下一个字符 } cout<<a<<":"<<b<<endl;//剩下的也要输完 cout<<endl;//换行隔开 a=b=0;i=0;//清零,换了一个分制 while(s1[i]!='E')//同理 { switch(s1[i]) { case 'W':a++;break; case 'L':b++;break; } if((a>=21||b>=21)&&(abs(a-b)>=2)) { cout<<a<<":"<<b<<endl; a=0;b=0; } i++; } cout<<a<<":"<<b<<endl; return 0; }
-
12017-10-08 10:26:56@
这一题真强,题目不难,坑点太多。
下面给一个代码,缩进我是调好的,如果错了就不要怪我#include <cstdio> char a[1000005]; int main(){ char c; c=getchar(); int len=0; while(c!='E'&&c!=EOF){ if(c=='W'||c=='L'){ a[++len]=c; } c=getchar(); } int awin=0,bwin=0; for(int i=1;i<=len;i++){ if(a[i]=='W'){ awin++; if(awin>=11&&awin-bwin>=2){ printf("%d:%d\n",awin,bwin); awin=0,bwin=0; } } if(a[i]=='L'){ bwin++; if(bwin>=11&&bwin-awin>=2){ printf("%d:%d\n",awin,bwin); awin=0,bwin=0; } } } printf("%d:%d\n",awin,bwin); awin=bwin=0; puts(""); for(int i=1;i<=len;i++){ if(a[i]=='W'){ awin++; if(awin>=21&&awin-bwin>=2){ printf("%d:%d\n",awin,bwin); awin=0,bwin=0; } } if(a[i]=='L'){ bwin++; if(bwin>=21&&bwin-awin>=2){ printf("%d:%d\n",awin,bwin); awin=0,bwin=0; } } } printf("%d:%d\n",awin,bwin); awin=bwin=0; return 0; }
-
02022-08-28 20:55:54@
#include<iostream>
#include<cmath>
using namespace std;char letter[100000];
void Output(int cap,int type) {
int w = 0, l = 0;
for (int i = 0; i < cap; i++) {
if (letter[i] == 'W')
w++;
if (letter[i] == 'L')
l++;
if (((w == type||l==type)&&(abs(l-w)>=2))||((w>type||l>type)&&(abs(l-w)==2)) ){
cout << w << ':' << l;
w = 0, l = 0;
cout << endl;
}
}
cout << w << ':' << l;
}
int main() {
int i = 0;
while ((letter[i] = getchar()) != EOF) {
if (letter[i] == 'E')
break;
i++;
}
Output(i, 11);
cout << endl<<endl;
Output(i, 21);return 0;
}
这位同学分析的很好,但是文字的排版有事也会被系统误判,记得小心哦! -
02022-03-28 22:37:58@
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
char competeCount[100000];
int main() {int hcount = 0, hcount2 = 0;
for (int i = 0;; i++) {
cin>>competeCount[i];
if (competeCount[i] == 'E')
break;}
//11读取
for (int i = 0;; i++) {
if (competeCount[i] == 'E') {
cout << hcount << ":" << hcount2 << endl;
hcount = 0;
hcount2 = 0;
break;
}
if (competeCount[i] == 'W')
hcount++;
if (competeCount[i] == 'L')
hcount2++;if ((hcount >= 11 || hcount2 >= 11) && (fabs(hcount - hcount2) >= 2)) {
cout << hcount << ":" << hcount2 << endl;
hcount = 0;
hcount2 = 0;
}}
cout << endl;
//21制读取
for (int i = 0;; i++) {
if (competeCount[i] == 'E') {
cout << hcount << ":" << hcount2 << endl;
break;
}
if (competeCount[i] == 'W')
hcount++;
if (competeCount[i] == 'L')
hcount2++;if ((hcount >= 21 || hcount2 >= 21) && (fabs(hcount - hcount2) >= 2)) {
cout << hcount << ":" << hcount2 << endl;
hcount = 0;
hcount2 = 0;
}}
return 0;
} -
02022-03-03 20:26:17@
answer:
#include<iostream> #include<cmath> using namespace std; char str[100010]; int cnt=0; void show(int n) { int a=0,b=0; for(int i=0;i<cnt;i++) { if(str[i]=='W') a++; if(str[i]=='L') b++; if((a>=n||b>=n)&&abs(a-b)>=2) { cout<<a<<":"<<b<<endl; a=b=0; } } cout<<a<<":"<<b<<endl; } int main() { char ch; while(cin>>ch&&ch!='E') { if(ch=='W'||ch=='L') { str[cnt++]=ch; } } show(11); cout<<endl; show(21); }
-
02021-12-22 17:08:32@
0
-
02021-11-03 19:09:07@
#include <cmath>
#include <stdio.h>
char in[1000000];void Result(int mode){
int W = 0, L = 0;
for (int i = 0; in[i] != '\0'; i++) {
switch (in[i]) {
case 'W':W++; break;
case 'L':L++; break;
}
if (((W >= mode)||(L >= mode)) && (abs(W - L) >= 2)) {
printf("%d:%d\n", W, L);
W = 0,L = 0;
}}
printf("%d:%d\n\n", W, L);
}int main()
{for (int i = 0; (scanf("%c", &in[i]) != EOF) && (in[i] != 'E'); i++, in[i + 1] = '\0') { if (in[i] == '\n')i--; }
Result(11);
Result(21);
return 0;
} -
02021-10-06 21:09:26@
use std::io; fn main() { let mut score: Vec<bool> = vec![]; 'out: loop { let mut line = String::new(); io::stdin().read_line(&mut line).expect("stdin"); for word in line.chars() { match word { 'W' => score.push(true), 'L' => score.push(false), 'E' => break 'out, _ => {} }; } } final_result(&score, 11); final_result(&score, 21); } fn final_result(score: &Vec<bool>, choice: i32) { let mut w = 0; let mut l = 0; for &i in score { if i { w += 1; } else { l += 1; } if (w >= choice || l >= choice) && ((w - l).abs() >= 2) { println!("{}:{}", w, l); w = 0; l = 0; } } println!("{}:{}\n", w, l); }
-
02020-04-10 16:09:57@
//就想知道凭什么难度是7 #include <iostream> //[2003普及组-A]乒乓球 #include <algorithm> #include <string> #include <cmath> using namespace std; void Print(string str, int k) { int a = 0, b = 0; for (int i = 0; i < str.length(); i++) if(str[i] != '\n') { if(str[i] == 'W') a++; else b++; if((a >= k || b >= k) && abs(a - b) >= 2) { cout << a << ":" << b << endl; a = 0, b = 0; } } cout << a << ":" << b << endl; } int main() { string str; getline(cin, str, 'E'); Print(str, 11); cout << endl; Print(str, 21); return 0; }
-
02020-03-17 18:51:52@
#include<iostream> #include<string> using namespace std; int main() { char str[1000005]; char ch; int ww = 0, ll = 0, len = 0; while((ch = getchar()) != 'E') { if(ch == '\n' || ch == ' ') continue; str[len++] = ch; } if(len == 0) { cout << "0:0" <<endl; cout << endl; cout << "0:0" <<endl; return 0; } //处理11分制 for(int i = 0 ; i < len; ++i) { bool flag = true; if(str[i] == 'W') ww++; else ll++; if(ww >= 11 && ww-ll > 1){ cout <<ww<<':'<<ll<<endl; ww = 0, ll = 0; } if(ll >= 11 && ll-ww > 1) { cout <<ww<<':'<<ll<<endl; ww = 0, ll = 0; } if(i == len - 1 && flag) { cout <<ww<<':'<<ll<<endl; ww = 0, ll = 0; } } cout << endl; for(int i = 0 ; i < len; ++i) { bool flag = true; if(str[i] == 'W') ww++; else ll++; if(ww >= 21 && ww-ll > 1){ cout <<ww<<':'<<ll<<endl; ww = 0, ll = 0; } if(ll >= 21 && ll-ww > 1) { cout <<ww<<':'<<ll<<endl; ww = 0, ll = 0; } if(i == len - 1) { cout <<ww<<':'<<ll<<endl; ww = 0, ll = 0; } } return 0; }
-
02020-03-10 19:21:10@
思路:循环逐个读字符,同时判断比赛情况,结束就储存,读到E跳出循环,循环外输出对局情况,记得输出没结束的对局
注意:题目没给好数据范围,一般考试不会这样,一般CE又WA就是数组开的不够大之类
#include <iostream> #include <cstdlib> using namespace std; int main() { int w11_tmp = 0, l11_tmp = 0, l21_tmp = 0, w21_tmp = 0, w11[10000], l11[10000], w21[10000], l21[10000], j11 = 0, j21 = 0; char c; for (;(c=getchar())!='E';) { if (c == 'W')++w11_tmp, ++w21_tmp; if (c == 'L')++l11_tmp, ++l21_tmp; if ((w11_tmp > 10 || l11_tmp > 10) && abs(w11_tmp - l11_tmp) > 1) w11[j11] = w11_tmp, l11[j11] = l11_tmp, ++j11, w11_tmp = l11_tmp = 0; if ((w21_tmp > 20 || l21_tmp > 20) && abs(w21_tmp - l21_tmp) > 1) w21[j21] = w21_tmp, l21[j21] = l21_tmp, ++j21, w21_tmp = l21_tmp = 0; } for (int i = 0; i < j11; ++i) printf("%d:%d\n", w11[i], l11[i]); printf("%d:%d\n\n", w11_tmp, l11_tmp); for (int i = 0; i < j21; ++i) printf("%d:%d\n", w21[i], l21[i]); printf("%d:%d", w21_tmp, l21_tmp); }
-
02020-02-01 16:34:48@
/*
这个题的测试数据太大了,数组一定要足够大才能全部通过
不然就会Runtime Error
*/
#include<iostream>
#include<cmath>using namespace std;
int main()
{
char contest[100000];
int total, win = 0, lose = 0;
for (total = 0;;) {
cin >> contest[total];
if (contest[total] == 'E' || contest[total] == EOF)break;
else if (contest[total] != ' '&& contest[total] != '\n')total++;
}
//11回合制
for (int i = 0; i < total; i++) {
if (contest[i] == 'W')win++;
else lose++;
if ((win >= 11 || lose >= 11) && abs(win - lose) >= 2) {
cout << win << ":" << lose << endl;
win = 0; lose = 0;
}
}
cout << win << ":" << lose << endl << endl;
//21回合制
win = 0; lose = 0;
for (int i = 0; i < total; i++) {
if (contest[i] == 'W')win++;
else lose++;
if ((win >= 21 || lose >= 21) && abs(win - lose) >= 2) {
cout << win << ":" << lose << endl;
win = 0; lose = 0;
}
}
cout << win << ":" << lose;
return 0;
}