阅读程序写结果
0 of 4 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 4 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
18题:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#include <stdio.h> int main() { int x; scanf("%d", &x); int res = 0; for (int i = 0; i < x; ++i) { if (i * i % x == 1) { ++res; } } printf("%d", res); return 0; } |
输入:5 输出:
19题:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#include <stdio.h> int n, d[100]; bool v[100]; int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", d + i); v[i] = false; } int cnt = 0; for (int i = 0; i < n; ++i) { if (!v[i]) { for (int j = i; !v[j]; j = d[j]) { v[j] = true; } ++cnt; } } printf("%d\n", cnt); return 0; } |
输入:10 7 1 4 3 2 5 9 8 0 6 输出:
20题:
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 |
#include <iostream> using namespace std; string s; long long magic(int l, int r) { long long ans = 0; for (int i = l; i <= r; ++i) { ans = ans * 4 + s[i] - ‘a’ + 1; } return ans; } int main() { cin >> s; int len = s.length(); int ans = 0; for (int l1 = 0; l1 < len; ++l1) { for (int r1 = l1; r1 < len; ++r1) { bool bo = true; for (int l2 = 0; l2 < len; ++l2) { for (int r2 = l2; r2 < len; ++r2) { if (magic(l1, r1) == magic(l2, r2) && (l1 != l2 || r1 != r2)) bo = false; } } if (bo) { ans += 1; } } } cout << ans << endl; return 0; } |
输入:abacba 输出:
21题:
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 |
#include <iostream> using namespace std; const int N = 110; bool isUse[N]; int n, t; int a[N], b[N]; bool isSmall() { for (int i = 1; i <= n; ++i) if (a[i] != b[i]) return a[i] < b[i]; return false; } bool getPermutation(int pos) { if (pos > n) { return isSmall(); } for (int i = 1; i <= n; ++i) { if (!isUse[i]) { b[pos] = i; isUse[i] = true; if (getPermutation(pos + 1)) { return true; } isUse[i] = false; } } return false; } void getNext() { for (int i = 1; i <= n; ++i) { isUse[i] = false; } getPermutation(1); for (int i = 1; i <= n; ++i) { a[i] = b[i]; } } int main() { scanf("%d%d", &n, &t); for (int i = 1; i <= n; ++i) { scanf("%d", &a[i]); } for (int i = 1; i <= t; ++i) { getNext(); } for (int i = 1; i <= n; ++i) { printf("%d", a[i]); if (i == n) putchar(’\n’); else putchar(’ '); } return 0; } |
输入1:6 10 1 6 4 5 3 2 输出:
输入2:6 200 1 5 3 4 2 6 输出: