381 条题解
-
0
VIJOS管理员----AFOer_LBW (超级牛逼卢本伟1号) LV 10 @ 2021-07-17 15:56:01
自动AC机直接过
-
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;
} -
02019-12-22 14:07:15@
#include <bits/stdc++.h>
using namespace std;
char ch[300000000];
int grade_w=0,grade_l=0;
void work(int n)
{
grade_w=0;grade_l=0;
int i=1;
while(ch[i]!='E')
{
if(ch[i]==' ')
continue;
if(ch[i]=='W') ++grade_w;
else if(ch[i]=='L') ++grade_l;if((grade_w>=n || grade_l>=n) && abs(grade_w-grade_l)>=2)
{
printf("%d:%d\n",grade_w,grade_l);
grade_w=0; grade_l=0;
}
++i;
}
printf("%d:%d\n",grade_w,grade_l);
}
int main()
{
int i=0;
do
scanf("%c",&ch[++i]);
while(ch[i]!='E');work(11);
printf("\n");
work(21);
return 0;
} -
02019-11-27 11:44:59@
#include<iostream> #include<cstring> #include<cstdlib> #include<cmath> using namespace std; string C[100000];//我也不知道它一共打了多少局,反正开始开100和1000都RE了 int main() { int Win1 = 0, Los1 = 0; int Win2 = 0, Los2 = 0;//21分制 string A; int cursor = 0; bool flag = true; while(cin>>A){//很多行字符串 for(int i = 0 ; i < A.length() ; i++){//每行 if(A[i] == 'W'){ Win1++; Win2++; } if(A[i] == 'L'){ Los1++; Los2++; } if(abs(Win1 - Los1) >= 2 && max(Win1, Los1) >= 11){ cout<<Win1<<":"<<Los1<<endl; Win1 = 0; Los1 = 0; } if(abs(Win2 - Los2) >= 2 && max(Win2, Los2) >= 21){ C[cursor++] = to_string(Win2) + ':' + to_string(Los2); Win2 = 0; Los2 = 0; } if(A[i] == 'E'){ flag = false; break; } } if(flag == false) break; } cout<<Win1<<":"<<Los1<<endl;//不完整的一段 cout<<endl; for(int i = 0 ; i < cursor ; i++) cout<<C[i]<<endl; cout<<Win2<<":"<<Los2<<endl;//不完整的一段 return 0; }
-
02019-11-14 23:19:33@
修复一下 2016wudi 的答案
#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;
int main()
{
string s1, s2;//方便输入
//cout << "请输入"<<endl;
while (true) {
getline(cin, s2);
s1 += s2;//输入字符串
if (s2.find('E') != string::npos)break;
}
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;
} -
02019-09-30 22:08:49@
emmmm......
-
02019-07-29 18:58:57@
#include<iostream>
#include<math.h>
using namespace std;char s[1024*1024];
void result(int length,int full){
int W=0,L=0;
for(int i=0;i<length;i++){
if(s[i]=='W')
W++;
else if(s[i]=='L')
L++;
if(max(W,L)>=full && abs(W-L)>=2){
cout<<W<<':'<<L<<endl;
W=L=0;
}
}
cout<<W<<':'<<L<<endl;
}int main(){
int i=0;
while((s[i] = getchar()) != EOF){
if(s[i]=='E')
break;
i++;
}
result(i,11);
cout<<endl;
result(i,21);
return 0;
}用上max()和abs()函数,会比较简洁
-
02019-06-07 13:45:50@
#include <iostream> #define f(x) ((x) < 0 ? (-(x)) : (x)) using namespace std; void match(string &s, int limit){ int k = 0, w = 0, l = 0; while(k < s.length()){ if(s[k] == ' '){ k++; continue; } if(s[k] == 'W') w++; if(s[k] == 'L') l++; k++; if((w >= limit || l >= limit) && f(w - l) > 1){ cout << w << ':' << l << endl; w = l = 0; } } cout << w << ':' << l << endl; putchar('\n'); return ; } int main(){ string s; string ans; while(getline(cin, s)){ if(s.find('E') == string::npos) ans.append(s); else{ ans.append(s.substr(0, s.find('E'))); break; } } match(ans, 11); match(ans, 21); return 0; }
-
02019-01-21 22:34:40@
被坑了两次😂😂😂第一次没看清输出,第二次数组太小😂😂😂
菜了菜了,还是来水一下题解吧#include <cstdio>
#include <cstring>
char s[100000];int abs(int a,int b)
{
int c;
if (a>b)
{
c=a-b;
}
if (b>a)
{
c=b-a;
}
return c;
}void output(int total,int type)
{
int w=0,l=0;
for (int i=0;i<=total;i++)
{
if (s[i]=='W')
{
w++;
}
if (s[i]=='L')
{
l++;
}
if (s[i]=='E')
{
printf("%d:%d\n",w,l);
}
if ((w>=type||l>=type)&&(abs(w,l)>1))
{
printf("%d:%d\n",w,l);
w=0;l=0;
}
}
}int main()
{
int i=0;
while (scanf("%c",&s[i])!=EOF)
{
if (s[i]=='E') break;
i++;
}
output(i,11);
printf("\n");
output(i,21);
return 0;
} -
02018-10-24 20:26:13@
小胖,你就骗下去吧,我也不揭穿你了。
-
02018-10-24 11:52:40@
这是我能想到的最简单的代码了,MAX=2000的时候有一个RE所以设置到了4000。
#include <iostream>
using namespace std;const int MAX=4000;
int a[MAX*2], b[MAX*2], c[MAX], d[MAX];int main(){
char ch;
int m=0, n=0;
while (cin>>ch && ch!='E'){
if (ch=='W'){
a[m]++;
c[n]++;
if (a[m]>=11 && a[m]-b[m]>1) m++;
if (c[n]>=21 && c[n]-d[n]>1) n++;
}
else{
b[m]++;
d[n]++;
if (b[m]>=11 && b[m]-a[m]>1) m++;
if (d[n]>=21 && d[n]-c[n]>1) n++;
}
}for (int i=0; i<=m; i++)
cout<<a[i]<<":"<<b[i]<<endl;
cout<<endl;
for (int i=0; i<=n; i++)
cout<<c[i]<<":"<<d[i]<<endl;return 0;
} -
02018-09-14 16:52:43@
fn process(contest_info: &str, max_score: i32) { let mut p1_score = 0; let mut p2_score = 0; for c in contest_info.chars() { if let 'W' = c { p1_score += 1; } else { p2_score += 1; } if (p1_score >= max_score || p2_score >= max_score) && (p1_score - p2_score).abs() >= 2 { println!("{}:{}", p1_score, p2_score); p1_score = 0; p2_score = 0; } } println!("{}:{}", p1_score, p2_score); } fn main() { let mut buf = String::new(); let mut contest_info = String::new(); let mut flag = true; while flag { std::io::stdin().read_line(&mut buf).unwrap(); contest_info.push_str(match buf.find('E') { Some(i) => { flag = false; &buf[..i] } None => buf.trim(), }); buf.clear(); } process(contest_info.as_str(), 11); println!(); process(contest_info.as_str(), 21); }
-
02018-08-25 21:29:15@
string='' def do_work(src): w = l = 0 for ch in string: if ch == 'E': print("{}:{}".format(w,l)) return elif ch == 'W': w += 1 elif ch == 'L': l += 1 if abs(w-l)>1 and (w>=src or l>=src): #print(w,':',l) print("{}:{}".format(w,l)) w = l = 0 while 1: s = input() string += s if s.find('E') != -1: break do_work(11) print() do_work(21)
这才叫简洁 kakaka
-
02018-08-05 22:05:50@
#include <stdio.h> #include <stdlib.h> int main() { int i = 0,game1 = 0,game2 = 0,flag = 0; int score1[10000][2],score2[10000][2]; char a[100000]; while((a[i] = getchar()) != 'E') { i++; } i = 0; do { score1[game1][0] = 0; score1[game1][1] = 0; while((score1[game1][0] < 11 && score1[game1][1] < 11)||abs(score1[game1][0] - score1[game1][1]) <= 1) { if(a[i] == 'W') { score1[game1][0]++; i++; } else if(a[i] == 'L') { score1[game1][1]++; i++; } else if(a[i] == 'E') { flag = 1; break; } else { i++; continue; } } game1++; if(!flag && a[i] == 'E') { game1++; score1[game1][0] = 0; score1[game1][1] = 0; } }while(a[i] != 'E'); i = 0; do { score2[game2][0] = 0; score2[game2][1] = 0; while((score2[game2][0] < 21 && score2[game2][1] < 21)||abs(score2[game2][0] - score2[game2][1]) <= 1) { if(a[i] == 'W') { score2[game2][0]++; i++; } else if(a[i] == 'L') { score2[game2][1]++; i++; } else if(a[i] == 'E') { flag = 1; break; } else { i++; continue; } } game2++; if(!flag && a[i] == 'E') { game2++; score2[game2][0] = 0; score2[game2][1] = 0; } }while(a[i] != 'E'); for(i = 0; i < game1; i++) printf("%d:%d\n",score1[i][0],score1[i][1]); printf("\n"); for(i = 0; i < game2; i++) printf("%d:%d\n",score2[i][0],score2[i][1]); return 0; }
-
02018-05-05 19:16:17@
//数组开10000会越界,要开100000
#include <iostream>
#include <cmath>
using namespace std;
int shu[100000];
int main(int argc, char** argv)
{
int s=0;//统计输入字母个数
while((shu[s]=getchar())!=EOF)
{
if(shu[s]=='E')
{
break;
}
s++;
}
int w=0;
int l=0;
for(int i=0;i<s;i++)
{
if(shu[i]=='W') w++;
if(shu[i]=='L') l++;
if(((w==11||l==11)&&abs(w-l)>=2)||((w>11||l>11)&&abs(w-l)==2))
{
cout<<w<<':'<<l<<endl;
w=0;
l=0;
}
}
cout<<w<<':'<<l<<endl<<endl;
w=0;
l=0;
for(int i=0;i<s;i++)
{
if(shu[i]=='W') w++;
if(shu[i]=='L') l++;
if((w==21||l==21)&&abs(w-l)>=2||(w>21||l>21)&&abs(w-l)==2)
{
cout<<w<<':'<<l<<endl;
w=0;
l=0;
}
}
cout<<w<<':'<<l<<endl;
return 0;
} -
02018-05-01 14:52:43@
Java表示,数据范围不需要的,这辈子都不可能需要的,Pascal,C,CPP会踩的坑,我们都可以跳过,数据我们可以边读边做,我们的数组还能自己变长,就是时间长了一点,但是能不用考虑坑就一次过那就都还好。
import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.Scanner; public class P1217 { static FileReader fr; static int n; static int score11a, score11b; static int score21a, score21b; static class Match{ int sc1, sc2; Match(int a, int b){ this.sc1 = a; this.sc2 = b; } public String toString() { return String.format("%d:%d", sc1, sc2); } } static ArrayList<Match> result11 = new ArrayList<Match>(); static ArrayList<Match> result21 = new ArrayList<Match>(); public static Scanner getInput() { return new Scanner(System.in); } // public static Scanner getInput() throws IOException { // File f = new File("input.txt"); // fr = new FileReader(f); // Scanner sc = new Scanner(fr); // // return sc; // } public static void input() throws IOException { Scanner sc = getInput(); boolean finished = false; while (!finished) { String s = sc.nextLine(); char[] c = s.toCharArray(); for (int i = 0; i < c.length; i++) { if (c[i] == 'E') { finished = true; result11.add(new Match(score11a, score11b)); result21.add(new Match(score21a, score21b)); break; } if (c[i] == 'W') { score11a++; score21a++; if (score11a >= 11 && score11b <= score11a - 2) { result11.add(new Match(score11a, score11b)); score11a = score11b = 0; } if (score21a >= 21 && score21b <= score21a - 2) { result21.add(new Match(score21a, score21b)); score21a = score21b = 0; } }else if (c[i] == 'L') { score11b++; score21b++; if (score11b >= 11 && score11a <= score11b - 2) { result11.add(new Match(score11a, score11b)); score11a = score11b = 0; } if (score21b >= 21 && score21a <= score21b - 2) { result21.add(new Match(score21a, score21b)); score21a = score21b = 0; } } } } if (fr != null) { fr.close(); } } public static void output() { for (int i = 0; i<result11.size(); i++) { System.out.println(result11.get(i)); } System.out.println(); for (int i = 0; i<result21.size(); i++) { System.out.println(result21.get(i)); } } public static void main(String args[]) throws IOException { input(); // algorithm(); output(); } }
-
02018-04-04 20:35:03@
做的麻烦了点 乒乓球分制不太懂 看了一下题解第一个的明白了!
#include <iostream>
#include <cmath>
using namespace std;
int main(){
char a[100000];
int hua=0,dui=0,i=0;
while ((a[i] = getchar()) != EOF) {
if (a[i] == 'E')
break;
i++;
}
for(int i=0;;i++){
if(a[i]=='W') hua++;
else if(a[i]=='L') dui++;
if(((hua==11||dui==11)&&(abs(hua-dui)>=2))||((hua>11||dui>11)&&(abs(hua-dui)==2))||a[i]=='E'){
cout<<hua<<":"<<dui<<endl;
hua=0;
dui=0;
}if(a[i]=='E') break;
}
cout<<endl;
for(int i=0;;i++){
if(a[i]=='W') hua++;
else if(a[i]=='L') dui++;
if(((hua==21||dui==21)&&(abs(hua-dui)>=2))||((hua>21||dui>21)&&(abs(hua-dui)==2))||a[i]=='E'){
cout<<hua<<":"<<dui<<endl;
hua=0;
dui=0;
}
if(a[i]=='E') break;
}}