当前位置:网站首页>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;
}
边栏推荐
- [document tree, setting] font becomes smaller
- 浏览器驱动的下载
- Chinese name extraction (toy code - accurate head is too small, right to play)
- 使用BLoC 构建 Flutter的页面实例
- 瀏覽器驅動的下載
- Let juicefs help you with "remote backup"
- Student course selection information management system based on ssm+jsp framework [source code + database]
- BeanUtils -- shallow copy -- example / principle
- 题解:《你的飞碟在这儿》、《哥德巴赫猜想》
- 大家信夫一站式信用平台让信用场景“用起来
猜你喜欢

selenium 元素定位方法

题解:《压缩技术》(原版、续集版)

Code implementation MNLM

MAC (MacOS Monterey 12.2 M1) personal use PHP development

Engineers who can't read device manuals are not good cooks

Solve "sub number integer", "jump happily", "turn on the light"

Essential for operation and maintenance - Elk log analysis system

Tupang multi-target tracking! BOT sort: robust correlated multi pedestrian tracking
![2022 zero code / low code development white paper [produced by partner cloud] with download](/img/46/92c51090e0c476df3bcffd2d11fb6d.png)
2022 zero code / low code development white paper [produced by partner cloud] with download

Integral link, inertia link and proportion link in Simulink
随机推荐
Qt-制作一个简单的计算器-实现四则运算
混沌工程平台 ChaosBlade-Box 新版重磅发布
De4000h storage installation configuration
2022零代码/低代码开发白皮书【伙伴云出品】附下载
D language, possible 'string plug-ins'
BeanUtils -- shallow copy -- example / principle
为什么switch 的default后面要跟break?
科技的成就(二十七)
浏览器驱动的下载
Winter vacation daily question - lucky numbers in the matrix
On flow delivery between microservices
BeanUtils--浅拷贝--实例/原理
P3008 [usaco11jan]roads and planes g (SPFA + SLF optimization)
How to explain binary search to my sister? This is really difficult, fan!
Development skills of rxjs observable custom operator
selenium 在pycharm中安装selenium
When tidb meets Flink: tidb efficiently enters the lake "new play" | tilaker team interview
瀏覽器驅動的下載
[technology development-22]: rapid overview of the application and development of network and communication technology-2-communication Technology
Bridge of undirected graph