当前位置:网站首页>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;
}
边栏推荐
- 大家信夫一站式信用平台让信用场景“用起来
- Solve "sub number integer", "jump happily", "turn on the light"
- A better database client management tool than Navicat
- [true topic of the Blue Bridge Cup trials 43] scratch space flight children's programming explanation of the true topic of the Blue Bridge Cup trials
- D how to check null
- 验证失败,请检查您的回电网址。您可以按照指导进行操作
- BeanUtils -- shallow copy -- example / principle
- Node.js通过ODBC访问PostgreSQL数据库
- OpenFOAM:lduMatrix&lduAddressing
- 免费SSL证书知多少?免费SSL证书和收费SSL证书的区别
猜你喜欢

What are eNB, EPC and PGW?

Research shows that "congenial" is more likely to become friends

题解:《你的飞碟在这儿》、《哥德巴赫猜想》

不会看器件手册的工程师不是个好厨子

BeanUtils--浅拷贝--实例/原理

When tidb meets Flink: tidb efficiently enters the lake "new play" | tilaker team interview

Don't spend money, spend an hour to build your own blog website

Use bloc to build a page instance of shutter

De4000h storage installation configuration

Skillfully use SSH to get through the Internet restrictions
随机推荐
Simple introduction to ENSP
Qt如何设置固定大小
2022零代码/低代码开发白皮书【伙伴云出品】附下载
Use of UIC in QT
OpenAPI generator: simplify the restful API development process
Bridge of undirected graph
[cloud native database] what to do when encountering slow SQL (Part 1)?
P3008 [USACO11JAN]Roads and Planes G (SPFA + SLF优化)
[indomitable medal activity] life goes on and writing goes on
Unity skframework framework (XII), score scoring module
Pattern matching and regular expressions in PostgreSQL - Das
Will your sleep service dream of the extra bookinfo on the service network
OpenFOAM:lduMatrix&lduAddressing
Answer: can the audio be set to on by default during easydss video on demand?
Daily practice of C language --- monkeys divide peaches
量子三体问题: Landau Fall
刚好1000粉丝,记录一下
What are eNB, EPC and PGW?
Qt入门-制作一个简易的计算器
Principle analysis of security rememberme