xtu oj 综合一

一.1075


#include <stdio.h>
int gcd(int x, int y){
    if(y == 0) return x;
    return gcd(y, x % y);
}
int main() {
    int x, y;
    while(scanf("%d%d", &x, &y) != EOF){
        if(x == y && x == 0) break;
        if(x < y){
            x ^= y;
            y ^= x;
            x ^= y;
        }
        printf("%d\n", x * y / gcd(x, y));
    }
    return 0;
}

二.1138

#include <stdio.h>
int gcd(int x, int y){
    if(y == 0) return x;
    return gcd(y, x % y);
}
int C(int x){
    return (x - 1) * x / 2;
}
int main() {
    int n, x, y;
    scanf("%d", &n);
    while(n--){
        scanf("%d%d", &x, &y);
        if(x == y) printf("0\n");
        else if(y == 0 || x == 2 || y == 1) printf("1\n");
        else {
            int s = C(x) - C(y), m = C(x);
            int z = gcd(m, s);
            printf("%d/%d\n", s / z, m / z);
        }
    }
    return 0;
}

三.1162

#include <stdio.h>
int main() {
    int n;
    while(scanf("%d", &n)){
        if(n == -1) break;
        int cnt = 0, x;
        for(int i = 0; i < 7; i++){
            if(n % 2 == 1) cnt++;
            n /= 2;
        }
        if(cnt % 2 == 0 && n == 0) printf("Yes\n");
        else if(cnt % 2 && n) printf("Yes\n");
        else printf("No\n");
    }
    return 0; 
}

四.1150

#include <stdio.h>
int main() {
    int arr[9];
    arr[0] = 1;
    for(int i = 1; i < 9; i++) arr[i] = arr[i - 1] * (i + 1);
    int n, flag = 0, i;
    while(scanf("%d", &n)!=EOF){
        for(i = 8; i >= 0; i--){
            if(n >= arr[i]) break;
        }
        if(n == 0) printf("0");
        while(i != -1){
            printf("%d", n / arr[i]);
            n %= arr[i];
            i--;
        }
        printf("\n");
    }
    return 0; 
}

五.1170

#include <stdio.h>
char min(char a, char b){
    return a < b ? a : b;
}
int main() {
    int n;
    while(scanf("%d", &n) != EOF && n != 0){
        char a[105], b[105], c[105];
        int d[5] = {0};
        scanf("%s", a);
        scanf("%s", b);
        scanf("%s", c);
        for(int  i = 0; i < n; i++){
            printf("%c", min(a[i], min(b[i], c[i])));
            d[min(a[i], min(b[i], c[i])) - 'A']++;
        }
        printf("\n");
        for(int i = 0; i < 5; i++){
            if(i != 0) printf(" ");
            printf("%d", d[i]);
        }
        printf("\n");
    }
    return 0;
}

六.1171

#include <stdio.h>
int main() {
    int n, arr1[40] = {0}, arr2[40] = {0};
    arr1[0] = 1, arr2[0] = 1;
    for(int i = 1; i < 40; i++){
        arr1[i] += arr2[i - 1];
        arr2[i] += arr1[i - 1] + arr2[i - 1];
        //printf("%d %d\n", arr1[i], arr2[i]);
    }
    while(scanf("%d", &n) !=EOF && n != 0){
        printf("%d\n", arr1[n - 1] + arr2[n - 1]);
    }
    return 0;
}

七.1172

#include <stdio.h>
int main() {
    int n;
    while(scanf("%d", &n) != EOF && n != 0){
        long long sum = 0;
        for(int  i = 1; i * i <= n; i++){
            if(n % i == 0) sum += i + n / i;
            if(i * i == n) sum -= i;
        }
        printf("%lld\n", sum);
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值