P1042 [NOIP2003 普及组] 乒乓球
题目链接:P1042 [NOIP2003 普及组] 乒乓球 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
#include <iostream>
#include <cmath>
using namespace std;
int res[100000];
int main() {
int cnt, a = 0, b = 0;
char c;
for (cnt = 0; cin >> c && c != 'E'; cnt++) {
if (c == 'W') {
res[cnt] = 1;
}
}
if (cnt == 0) {
cout << "0:0" << endl;
cout << endl;
cout << "0:0";
return 0;
}
//11分制
for (int i = 0; i < cnt; i++) {
if (res[i] == 1) {
a++;
} else {
b++;
}
if ((a >= 11 || b >= 11) && abs(a - b) >= 2) {
cout << a << ':' << b << endl;
a = b = 0;
}
}
cout << a << ':' << b << endl;
cout << endl;
a = b = 0;
//21分制
for (int i = 0; i < cnt; i++) {
if (res[i] == 1) {
a++;
} else {
b++;
}
if ((a >= 21 || b >= 21) && abs(a - b) >= 2) {
cout << a << ':' << b << endl;
a = b = 0;
}
}
cout << a << ':' << b << endl;
return 0;
}
P2670 [NOIP2015 普及组] 扫雷游戏
题目链接:P2670 [NOIP2015 普及组] 扫雷游戏 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
#include <iostream>
using namespace std;
int a[105][105];
int main() {
int n, m;
cin >> n >> m;
char c;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> c;
if (c == '*') {
a[i][j] = 1;
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (a[i][j] == 1) {
cout << '*';
} else {
cout << a[i + 1][j + 1] + a[i][j + 1] + a[i + 1][j] + a[i - 1][j - 1] + a[i - 1][j] + a[i][j - 1] + a[i - 1][j + 1] +
a[i + 1][j - 1];
}
}
cout << endl;
}
return 0;
}
P1563 [NOIP2016 提高组] 玩具谜题
题目链接:P1563 [NOIP2016 提高组] 玩具谜题 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Person {
public:
string name;
int flag;
};
Person p[100005];
int main() {
int n, m, a, b, index = 0;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> p[i].flag >> p[i].name ;
}
for (int i = 0; i < m; i++) {
cin >> a >> b;
if (a ^ p[index].flag) {
index = (index + b) % n;
} else {
if (index - b >= 0) {
index -= b;
} else {
index = n - (abs(index - b) % n);
}
}
}
cout << p[index].name ;
return 0;
}
P1601 A+B Problem(高精)
题目链接:P1601 A+B Problem(高精) - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
#include <iostream>
#include <string>
using namespace std;
int main() {
string a, b;
cin >> a >> b;
if (a.size() > b.size()) {
for (int i = b.size(); i < a.size(); i++) {
b = '0' + b;
}
} else if (a.size() < b.size()) {
for (int i = a.size(); i < b.size(); i++) {
a = '0' + a;
}
}
int c, d;
for (int i = a.size() - 1; i >= 0; i--) {
c = (a[i] - '0' + b[i] - '0') % 10;
d = (a[i] - '0' + b[i] - '0') / 10;
a[i] = c + '0';
if (i != 0) {
a[i - 1] += d;
} else if (d != 0 && i == 0) {
cout << d;
}
}
cout << a;
return 0;
}
P1303 A*B Problem
题目链接:P1303 A*B Problem - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
#include <iostream>
#include <string>
#include <algorithm>
us