23 年冬季学期 22 级 ACM 新生杯热身赛

C++, Ivan Chien

A:

1#include <bits/stdc++.h>
2
3int main() {
4    std::cout << "65721016777" << std::endl;
5}

B:

 1#include <bits/stdc++.h>
 2
 3int main() {
 4    int n, m, a;
 5    std::cin >> n >> m;
 6    int sum = 0;
 7    for (int i = 0; i < n; ++i) {
 8        std::cin >> a;
 9        sum += a;
10    }
11    std::cout << std::min(sum, m) << std::endl;
12}

C:

 1#include <bits/stdc++.h>
 2
 3void solve() {
 4    char c;
 5    if (std::cin >> c) {
 6        solve();
 7        std::cout << c;
 8    }
 9}
10
11int main()
12{
13    ::solve();
14    std::cout << std::endl;
15}

D:

 1#include <bits/stdc++.h>
 2
 3int main() {
 4    int n;
 5    std::cin >> n;
 6    std::vector<int> a(n);
 7    for (int i = 0; i < n; ++i)
 8        std::cin >> a[i];
 9    std::sort(a.begin(), a.end());
10    for (int i = 0; i < n; ++i)
11        std::cout << a[i] << " \n"[i == n-1];
12}

E:

 1#include <bits/stdc++.h>
 2
 3int main() {
 4    int n;
 5    std::cin >> n;
 6    int sum = n;
 7    while (n >= 3) {
 8        sum += n / 3;
 9        n = n % 3 + n / 3;
10    }
11    std::cout << sum << std::endl;
12}

F:

 1#include <bits/stdc++.h>
 2
 3int gcd(int n, int m) {
 4    return m == 0 ? n : gcd(m, n % m);
 5}
 6
 7int main() {
 8    int n, m;
 9    std::cin >> n >> m;
10    std::cout << n / ::gcd(n, m) * m << std::endl;
11}

C, dengyue

A:

1#include <stdio.h>
2int main() {
3    printf("65721016777");
4    return 0;
5}

B:

 1#include <stdio.h>
 2int main() {
 3    int n, m;
 4    int sum = 0;;
 5    int a[10000];
 6    scanf("%d %d", &n, &m);
 7    for (int i = 0; i < n; i++) {
 8        scanf("%d", &a[i]);
 9        sum = sum + a[i];
10    }
11    if(sum > m) {
12        printf("%d", m);
13    }else {
14        printf("%d", sum);
15    }
16    return 0;
17}

C:

 1#include <stdio.h>
 2#include <stdlib.h>
 3#include <string.h>
 4int main() {  
 5    int len, i;
 6    char a[100000];
 7    gets(a);
 8    len = strlen(a);
 9    for(i = len - 1; i >= 0; i--)
10        printf("%c", a[i]);
11
12    return 0;
13}

D:

 1#include <stdio.h>
 2int main() {
 3    int a[1000000];
 4    int n;
 5    int i, j, m, temp;
 6    scanf("%d", &n);
 7    for( i = 0; i < n; i++)
 8        scanf("%d", &a[i]);
 9    for( i = 0; i < n-1; i++) {
10        m = i;  
11        for( j = i + 1; j < n; j++) 
12            if(a[j] < a[m])        
13                m = j;    
14        if(m != i) {
15            temp = a[i];
16            a[i] = a[m];
17            a[m] = temp;
18        }
19    }
20    for( j = 0; j < n; j++)
21        printf("%d ", a[j]);
22    printf("\n");
23}

E:

 1#include <stdio.h>
 2int main() {
 3    int n;
 4    scanf("%d", &n);
 5    int ans = n;
 6    while(n >= 3) {
 7        ans += n / 3;
 8        n = n / 3 + n % 3;
 9    }
10    printf("%d", ans);
11    return 0;
12}

F:

 1#include <stdio.h>
 2int main() {
 3    int a, b;
 4    int i, k;
 5    int temp;
 6    scanf("%d %d", &a, &b);
 7    i = a * b;
 8    while(b != 0) {
 9        temp = a % b;
10        a = b;
11        b = temp;
12    }
13    k = i / a;
14    printf("%d", k);
15}