2018 Autumn 清北学堂普及刷题班 Day2 题解

由于缺少题面,故本篇无内容。

这里仅提供T1. coin的代码实现。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* -- Basic Headers -- */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <algorithm>

/* -- STL Iterator -- */
#include <vector>
#include <string>
#include <stack>
#include <queue>

/* -- Defined Functions -- */
#define For(a,x,y) for (int a = x; a <= y; ++a)
#define Bak(a,y,x) for (int a = y; a >= x; --a)
using namespace std;

namespace FastIO {
void DEBUG(char comment[], int x) {
cerr << comment << x << endl;
}

inline int getint() {
int s = 0, x = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') x = -1;
ch = getchar();
}
while (isdigit(ch)) {
s = s * 10 + ch - '0';
ch = getchar();
}
return s * x;
}
inline void __basic_putint(int x) {
if (x < 0) {
x = -x;
putchar('-');
}
if (x >= 10) __basic_putint(x / 10);
putchar(x % 10 + '0');
}

inline void putint(int x, char external) {
__basic_putint(x);
putchar(external);
}
}

namespace Solution {
// 中国有句古话叫做闷声ACCEPT
// 我就什么都不写,才是坠吼的
}

int main(int argc, char *const argv[]) {
#ifndef HANDWER_FILE
freopen("coin.in", "r", stdin);
freopen("coin.out", "w", stdout);
#endif
int t;
cin >> t;
char c;
int x = 0, X = 0;
while (t --> 0) {
cin >> c;
switch(c) {
case 'x' :
++x;
break;
case 'X' :
++X;
break;
}
}
if (x == X) {
puts("0");
return 0;
}
int cnt = 0;
if (x < X) {
while (x != X) {
++x, --X, ++cnt;
}
}
if (X < x) {
while (x != X) {
++X, --x, ++cnt;
}
}
FastIO::putint(cnt, '\n');
return 0;
}