// 取消cin和cout的绑定 std::cin.tie(NULL); /*等价于cin.tie(0);*/ int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) cin >> b[i]; while (m--) { int op; cin >> op; if (op == 1) { int a1, b1, c1; cin >> a1 >> b1 >> c1; for (int i = 0; i < c1; i++) { b[b1 + i] = a[i + a1]; } }
if (op == 2) { int pos; cin >> pos; cout << b[pos] << endl; } } }
#include<algorithm> #include<iostream> usingnamespace std; string s; intmain(){ int t; longlong sx, sy, ex, ey; cin >> t >> sx >> sy >> ex >> ey; if (sx == ex && sy == ey) { printf("0"); return0; } cin >> s; for (int i = 0; i < t; i++) { if (s[i] == 'E' && sx < ex) sx += 1; elseif (s[i] == 'W' && sx > ex) sx -= 1; elseif (s[i] == 'N' && sy < ey) sy += 1; elseif (s[i] == 'S' && sy > ey) sy -= 1; if (sx == ex && sy == ey) { printf("%d", i + 1); return0; } } printf("-1"); return0; }
3157: IQ Test
判断数列是等差还是等比,输出下一项;若不是则输出42。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include<iostream> #include<algorithm> usingnamespace std; int a, b, c, d; intmain() { cin >> a >> b >> c >> d; if (a - b == b - c && b - c == c - d) //等差 cout << d - (a - b); elseif (a * c == b * b && d * b == c * c) //等比 if (d * d % c) cout << "42"; else cout << d * d / c; else cout << "42"; return0; }