当前位置:网站首页>P1042 [NOIP2003 普及组] 乒乓球
P1042 [NOIP2003 普及组] 乒乓球
2022-07-02 10:20:00 【fu福寿草】
坑点1:E会在任意位置出现, 不一定是结尾。
坑点2:输赢只差必须大于等于2场
坑点3:读到E时,不论比分是否为零,都要输出
字符串模拟版本:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
void solve() {
string s;
char c = cin.get();
while (c != 'E') {
if (c == 'W' || c == 'L') s += c;
c = cin.get();
}
int w = 0, l = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'W') {
w++;
} else if (s[i] == 'L') {
l++;
}
if (abs(w - l) >= 2 && (w >= 11 || l >= 11)) {
cout << w << ":" << l << "\n";
w = l = 0;
}
}
cout << w << ":" << l << "\n\n";
w = l = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'W') {
w++;
} else if (s[i] == 'L') {
l++;
}
if (abs(w - l) >= 2 && (w >= 21 || l >= 21)) {
cout << w << ":" << l << "\n";
w = l = 0;
}
}
cout << w << ":" << l << "\n";
}
int32_t main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int tt(1);
//std::cin >> tt;
while (tt--) {
solve();
}
return 0;
}
数组模拟版本:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
constexpr int N = 2500 * 30;
int win[N];
void solve() {
char c = cin.get();
int tot = 0;
while (c != 'E') {
if (c == 'W') {
win[tot++] = 1;
} else if (c == 'L') {
win[tot++] = 2;
}
c = cin.get();
}
int w = 0, l = 0;
for (int i = 0; i <= tot; i++) {
if (win[i] == 1) {
w++;
} else if (win[i] == 2) {
l++;
}
if (i == tot || abs(w - l) >= 2 && (w >= 11 || l >= 11)) {
cout << w << ":" << l << "\n";
w = l = 0;
}
}
cout << "\n";
for (int i = 0; i <= tot; i++) {
if (win[i] == 1) {
w++;
} else if (win[i] == 2) {
l++;
}
if (i == tot || abs(w - l) >= 2 && (w >= 21 || l >= 21)) {
cout << w << ":" << l << "\n";
w = l = 0;
}
}
cout << "\n";
}
int32_t main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int tt(1);
//std::cin >> tt;
while (tt--) {
solve();
}
return 0;
}
边栏推荐
- 故事点 vs. 人天
- JS reverse massive creative signature
- (POJ - 1984) navigation nightare (weighted and search set)
- Use bloc to build a page instance of shutter
- SSL证书的分类有哪些?如何选择合适的SSL证书?
- Fundamentals of machine learning (II) -- division of training set and test set
- Student course selection information management system based on ssm+jsp framework [source code + database]
- Answer: can the audio be set to on by default during easydss video on demand?
- 免费SSL证书知多少?免费SSL证书和收费SSL证书的区别
- A better database client management tool than Navicat
猜你喜欢
2022 Heilongjiang provincial examination on the writing skills of Application Essays
Memory management 01 - link script
Why is the default of switch followed by break?
Code implementation MNLM
Explanation: here is your UFO, Goldbach conjecture
uniapp小程序 subPackages分包配置
Bridge of undirected graph
ensp简单入门
Essential for operation and maintenance - Elk log analysis system
题解:《你的飞碟在这儿》、《哥德巴赫猜想》
随机推荐
【模板】最长公共子序列 (【DP or 贪心】板子)
2022 zero code / low code development white paper [produced by partner cloud] with download
[usaco05jan]watchcow s (Euler loop)
混沌工程平台 ChaosBlade-Box 新版重磅发布
Don't spend money, spend an hour to build your own blog website
Can automatically update the universal weekly report template, you can use it with your hand!
693. 行程排序(map + 拓扑)
Memory management 01 - link script
P1347 sorting (topology + SPFA judgment ring or topology [inner judgment ring])
selenium 在pycharm中安装selenium
[技术发展-22]:网络与通信技术的应用与发展快速概览-2- 通信技术
Runhe hi3516 development board openharmony small system and standard system burning
Quantum three body problem: Landau fall
Astro learning notes
De4000h storage installation configuration
浏览器驱动的下载
Three methods of finding LCA of the nearest common ancestor
mysql ---- Oracle中的rownum转换成MySQL
2、 Frame mode MPLS operation
How to use SAP's metadata framework (MDF) to build custom business rules?