int a, b, c, d; intmain(){ cin >> a >> b >> c >> d; int t1 = a * 60 + b; int t2 = c * 60 + d; if (t2 < t1) t2 += 24 * 60; int h = (t2 - t1) / 60, m = (t2 - t1) % 60; if (h == 0 && m == 0) cout << "O JOGO DUROU 24 HORA(S) E 0 MINUTO(S)" << endl; else printf("O JOGO DUROU %d HORA(S) E %d MINUTO(S)\n", h, m); return0; }
intmain(){ ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int t; cin >> t; string a, b; for (int i = 0; i < t; i++) { cin >> a >> b; if (a == b) cout << "Repetition" << endl; if (a == "Scissors" && b == "Paper") cout << "Player1" << endl; if (a == "Scissors" && b == "Rock") cout << "Player2" << endl; if (a == "Paper" && b == "Rock") cout << "Player1" << endl; if (a == "Paper" && b == "Scissors") cout << "Player2" << endl; if (a == "Rock" && b == "Scissors") cout << "Player1" << endl; if (a == "Rock" && b == "Paper") cout << "Player2" << endl; } return0; }
usingnamespace std; int n; int res; boolisprime(int n){ if (n <= 1) returnfalse; for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0) returnfalse; } returntrue; } intmain(){ ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n; for (int i = 1; i < n; i++) if (n % i == 0 && !isprime(i)) res += i; cout << res << endl; return0; }
#include<algorithm> #include<cstring> #include<iostream> #include<queue> usingnamespace std; typedef pair<int, int> PII; constint N = 25; // 存雷,true 表示有雷 bool mp[N][N]; // 是否已经打开 int st[N][N]; // row col 雷数量 int n, m, k, l;
int bx[] = {-1, -1, -1, 0, 0, 1, 1, 1}, by[] = {-1, 0, 1, -1, 1, -1, 0, 1}; // 算一算八个方向有几个雷 voidcount(int x, int y){ st[x][y] = 0; for (int i = 0; i < 8; i++) { int nx = x + bx[i], ny = y + by[i]; if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue; if (mp[nx][ny]) st[x][y]++; } }
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1}; // bfs 打开周围没雷的格子 voidbfs(int x, int y){ queue<PII> q; q.push({x, y}); count(x, y); while (!q.empty()) { int x = q.front().first, y = q.front().second; q.pop(); for (int i = 0; i < 4; ++i) { int nx = x + dx[i], ny = y + dy[i]; if (nx < 0 || nx >= m || ny < 0 || ny >= n) continue; if (!mp[nx][ny] && st[nx][ny] == -1) { count(nx, ny); q.push({nx, ny}); } } } }
booltap(int x, int y){ // 越界 if (x < 0 || x >= m || y < 0 || y >= n) returnfalse; // 如果开过了 if (st[x][y] != -1) returnfalse; // 如果这里是雷,那么就是死亡 if (mp[x][y]) returntrue; // 把旁边点开 bfs(x, y); returnfalse; } bool flag = false; intmain(){ cin >> n >> m >> k >> l; for (int i = 0; i < k; i++) { int x, y; cin >> x >> y; mp[x][y] = true; } memset(st, -1, sizeof(st)); for (int i = 0; i < l; i++) { int x, y; cin >> x >> y; if (tap(x, y)) { cout << "You lose" << endl; flag = true; break; } else { for (int ii = 0; ii < n; ii++) { for (int jj = 0; jj < m; jj++) printf("%d ", st[ii][jj]); cout << endl; } } if (i != l - 1) cout << endl; } int cnt = 0; if (!flag) { for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) if (st[i][j] == -1) cnt++; // cout << cnt << endl; if (cnt == k) cout << "You win" << endl; } return0; }
intmain(){ cin >> n; for (int i = 0; i < n; i++) { float h, w; cin >> h >> w; float s = 2 * (h - 100) * 0.9;
if (abs(s - w) < s * 0.1) cout << "You are wan mei!" << endl; elseif (w <= s) cout << "You are tai shou le!" << endl; else cout << "You are tai pang le!" << endl; }
intmain(){ cin >> n >> c; getline(cin, s); getline(cin, s); if (s.size() > n) { // 切除 s = s.substr(s.size() - n); } else { // 补充 int t = n - s.size(); for (int i = 0; i < t; i++) s = c + s; } cout << s << endl; return0; }
#include<algorithm> #include<cmath> #include<cstring> #include<iostream> #include<map> usingnamespace std; int n, m; int maxn = -0x3f3f3f3f, maxid = -0x3f3f3f3f; map<int, int> ma;
intmain(){ ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> m; int id; for (int j = 0; j < m; j++) { cin >> id; ma[id]++; if ((ma[id] > maxn) || (ma[id] == maxn && id > maxid)) { maxn = ma[id]; maxid = id; } } }
intmain(){ int a, b; cin >> a >> b; if (b == 0) cout << a << "/0=Error"; if (b < 0) printf("%d/(%d)=%.2f", a, b, (float)a / b); if (b > 0) printf("%d/%d=%.2f", a, b, (float)a / b); cout << endl; return0; }
#include<algorithm> #include<cmath> #include<cstring> #include<iostream> usingnamespace std; int n;
intmain(){ cin >> n; for (int i = 0; i < n; i++) { char a; double b; cin >> a >> b; if (a == 'F') printf("%.2f\n", b * 1.09); else printf("%.2f\n", b / 1.09); } return0; }
intmain(){ getline(cin, a); getline(cin, b); for (int i = 0; i < b.size(); i++) s.insert(b[i]); for (int i = 0; i < a.size(); i++) if (!s.count(a[i])) cout << a[i]; cout << endl; return0; }
intmain(){ cin >> n; while (n--) { string id; cin >> id; int sum = 0; for (int i = 0; i < 17; i++) sum += (id[i] - '0') * k[i]; if (id[17] != s[sum % 11]) { cout << id << endl; flag = false; } } if (flag) cout << "All passed" << endl; return0; }
intmain(){ scanf("%d:%d", &h, &m); if (h >= 0 && h <= 12) { printf("Only %02d:%02d. Too early to Dang.", h, m); } else { if (m == 0) { for (int i = 0; i < h - 12; i++) cout << "Dang"; } else { for (int i = 0; i <= h - 12; i++) cout << "Dang"; } cout << endl; }
intmain(){ cin >> ca >> cb; ba = ca, bb = cb; cin >> n; for (int i = 0; i < n; i++) { int flag = 1; int a, b, c, d; // 甲喊 甲划 乙喊 乙划 cin >> a >> b >> c >> d; // 如果谁比划出的数字正好等于两人喊出的数字之和 if (b == a + c) flag *= -1; if (d == a + c) flag *= -1; if (flag != 1) { if (b == a + c) --ca; if (d == a + c) --cb; if (ca < 0) { cout << 'A' << endl << bb - cb << endl; break; } if (cb < 0) { cout << 'B' << endl << ba - ca << endl; break; } } } return0; }
int n, k; set<int> s, q; vector<int> v; bool flag;
intmain(){ scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &k); for (int i = 0; i < k; i++) { int tmp; scanf("%d", &tmp); s.insert(tmp); } }
scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &k); if (!q.count(k) && !s.count(k)) { flag = true; v.push_back(k); q.insert(k); } } if (!flag) printf("No one is handsome\n"); else { for (int i = 0; i < v.size(); i++) { printf("%d", v[i]); if (i != v.size() - 1) printf(" "); } puts(""); } return0; }
intmain(){ cin >> n >> c; a = n; // 第一层 a--, n--; v.push_back(1); // 枚举看看有几层 for (int i = 2; i < 100; i++) { int t = 2 * (2 * i - 1); a -= t; if (a < 0) break; sum += t; v.push_back(2 * i - 1); }
for (int i = v.size() - 1; i >= 0; i--) { for (int j = 1; j <= (v[v.size() - 1] - v[i]) / 2; j++) cout << ' '; for (int j = 1; j <= v[i]; j++) cout << c; cout << endl; } for (int i = 1; i < v.size(); i++) { for (int j = 1; j <= (v[v.size() - 1] - v[i]) / 2; j++) cout << ' '; for (int j = 1; j <= v[i]; j++) cout << c; cout << endl; } // 输出剩下的数字 cout << n - sum << endl; return0; }
L1-003 个位数统计 (15 分)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include<algorithm> #include<cstring> #include<iostream> #include<map> #define x first #define y second usingnamespace std;
string n; map<int, int> m;
intmain(){ cin >> n; for (int i = 0; i < n.size(); i++) m[n[i] - '0']++;
for (auto node : m) cout << node.x << ':' << node.y << endl;
#include<algorithm> #include<cstring> #include<iostream> usingnamespace std; constint N = 110; // 题目要求长整型范围 typedeflonglong LL; int n; LL a[N], b[N]; LL sum;
LL gcd(int a, int b){ return b ? gcd(b, a % b) : a; }
LL lcm(int a, int b){ return a * b / gcd(a, b); }
intmain(){ scanf("%d", &n); int m = 1; for (int i = 0; i < n; i++) { scanf("%lld/%lld", &a[i], &b[i]); m = lcm(m, b[i]); } for (int i = 0; i < n; i++) { a[i] *= (m / b[i]); sum += a[i]; } // 处理数字 LL t = gcd(sum, m); sum /= t; m /= t; // 特判负号 if (sum < 0) { cout << '-'; sum = abs(sum); } if (sum % m == 0) // 是不是整数 cout << sum / m << endl; elseif (sum < m) // 有没有整数 cout << sum % m << '/' << m << endl; else cout << sum / m << ' ' << sum % m << '/' << m << endl; return0; }
题目描述 You’ve got a recipe which specifies a number of ingredients, the amount of each ingredient you will need, and the number of portions it produces. But, the number of portions you need is not the same as the number of portions specified in the recipe! How can you scale it? 输入 The first line of input contains three integers n (1 ≤ n ≤ 40), x and y (1 ≤ x, y ≤ 40,000), where n is the number of ingredients in the recipe, x is the number of portions that the recipe produces, and y is the number of portions you need. Each of the next n lines contains a single integer a (1 ≤ a ≤ 40,000). These are the amounts of each ingredient needed for the recipe. The inputs will be chosen so that the amount of each ingredient needed for y portions will be an integer. 输出 Output n lines. On each line output a single integer, which is the amount of that ingredient needed to produce y portions of the recipe. Output these values in the order of the input. 【样例输入1】 2 4 10 8 12 【样例输入2】 3 37627 38021 34571 38009 34189 【样例输出1】 20 30 【样例输出2】 34933 38407 34547
typedeflonglong LL; constint N = 500; LL n, x, y; LL a[N];
intmain(){ cin >> n >> x >> y; for (int i = 0; i < n; i++) scanf("%lld", &a[i]); for (int i = 0; i < n; i++) printf("%lld\n", a[i] * y / x); return0; }
题目描述 A computer at ICPC headquarters is protected by a four-digit password—in order to log in, you normally need to guess the four digits exactly. However, the programmer who implemented the password check left a backdoor in the computer—there is a second four-digit password. If the programmer enters a four-digit sequence, and for each digit position the digit entered matches at least one of the two passwords in that same position, then that four-digit sequence will log the programmer into the computer. Given the two passwords, count the number of distinct four-digit sequences that can be entered to log into the computer. 输入 The input consists of exactly two lines. Each of the two lines contains a string s (|s| = 4, s ∈ {0-9} ∗ ). These are the two passwords. 输出 Output a single integer, which is the number of distinct four-digit sequences that will log the programmer into the system. 【样例输入1】 1111 1234 【样例输入2】 2718 2718 【样例输出1】 8 【样例输出2】 1
#include<algorithm> #include<climits> #include<cstring> #include<iostream> usingnamespace std; constint N = 10010;
typedeflonglong LL;
boolcmp(LL a, LL b){ return a > b; } LL n; LL a[N], b[N]; LL ans; intmain(){ scanf("%lld", &n); for (int i = 0; i < n; i++) scanf("%lld", &a[i]); for (int i = 0; i < n; i++) scanf("%lld", &b[i]); sort(a, a + n); sort(b, b + n, cmp); for (int i = 0; i < n; i++) ans += abs(a[i] - b[i]); printf("%lld\n", ans); return0; }
intmain(){ scanf("%d", &T); longlong n; while (T--) { scanf("%lld", &n); memset(w, 0, sizeof w); memset(m, 0, sizeof m); for (longlong i = 0; i < n; i++) scanf("%lld", &w[i]); for (longlong i = 0; i < n; i++) scanf("%lld", &m[i]); sort(w, w + n); sort(m, m + n, cmp); longlong res = 0; for (longlong i = 0; i < n; i++) res += (longlong)w[i] * m[i]; printf("%lld\n", res); } return0; }
两个字母之间的距离定义为它们在字母表中位置的距离。例如 A 和 C 的距离为 2,L 和 Q 的距离为 5。
对于一个字符串,我们称字符串中两两字符之间的距离之和为字符串的内部距离。
例如:ZOO 的内部距离为 22,其中 Z 和 O 的距离为 11。
请问,LANQIAO 的内部距离是多少?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream> #include <cmath>
using namespace std;
int main() { string s = "LANQIAO"; int res = 0; for (int i = 0; i < s.size() - 1; i ++ ) for (int j = i + 1; j < s.size(); j ++ ) res += abs(s[i] - s[j]); cout << res << endl; return 0; }
int res = 0; while (!q.empty()) { auto t = q.front(); for (int i = 0; i < 4; i++) { int x = t.x + dx[i], y = t.y + dy[i]; // if (x < 0 || y < 0) continue; if (m[x][y]) continue; // 没选过 m[x][y] = true; q.push({x, y}); cnt++; } // 把头元素加入队列方便计数 if (t.x == 3000 && t.y == 3000) { q.push({3000, 3000}); res++; } if (res == 2021) break;