信息学奥赛

2059 买笔

#include <stdio.h>  
  
int main() {  
    int x;  
    int sixYuanPens = 0, fiveYuanPens = 0, fourYuanPens = 0; 
    int found = 0;   
    scanf("%d", &x);   
    for (sixYuanPens = 0; sixYuanPens * 6 <= x; sixYuanPens++) {  
        for (fiveYuanPens = 0; (sixYuanPens * 6 + fiveYuanPens * 5) <= x; fiveYuanPens++) {  
            int remainingMoney = x - (sixYuanPens * 6 + fiveYuanPens * 5);  
            fourYuanPens = remainingMoney / 4;  
            if ((sixYuanPens * 6 + fiveYuanPens * 5 + fourYuanPens * 4) == x) {  
                found = 1;  
                printf("%d %d %d\n", sixYuanPens, fiveYuanPens, fourYuanPens);   
                break;  
            }  
        }  
     
        if (found) break;  
    }  
  
    return 0;  
}

1051 分段函数

#include <stdio.h>  
  
int main() {  
    double x, y;  
 
    scanf("%lf", &x);    
    if (x >= 0 && x < 5) {  
        y = -x + 2.5;  
    } else if (x >= 5 && x < 10) {  
        y = 2 - 1.5 * (x - 3) * (x - 3);  
    } else if (x >= 10 && x < 20) {  
        y = x / 2 - 1.5;  
    } else {    
        printf("x的值不在定义的区间内。\n");  
        return 1;  
    }  
    printf("%.3lf\n", y);  
  
    return 0; 
}

1050  骑车与走路

#include <stdio.h>  
  
int main() {  
    double distance; // 距离,单位:米  
    double bikeTime, walkTime; // 骑车和步行所需时间,单位:秒  
    double bikeFixedTime = 27 + 23; // 骑车固定时间(找车、开锁、停车、锁车),单位:秒  
    double bikeSpeed = 3.0; // 骑车速度,单位:米/秒  
    double walkSpeed = 1.2; // 步行速度,单位:米/秒  
  
    scanf("%lf", &distance);  
  
    // 计算骑车所需时间  
    bikeTime = bikeFixedTime + distance / bikeSpeed;  
  
    // 计算步行所需时间  
    walkTime = distance / walkSpeed;  
  
    // 比较两者时间并输出结果  
    if (bikeTime < walkTime) {  
        printf("Bike\n");  
    } else if (bikeTime > walkTime) {  
        printf("Walk\n");  
    } else {  
        printf("All\n");  
    }  
  
    return 0;  
}

1055 判断闰年

#include <stdio.h>  
  
int main() {  
    int year;  
  
    // 提示用户输入年份   
    scanf("%d", &year);  
  
    // 判断是否是闰年  
    if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {  
        printf("Y\n");  
    } else {  
        printf("N\n");  
    }  
  
    return 0;  
}

1054 三角形判断

#include <stdio.h>  
  
int main() {  
    int a, b, c;  
  
    // 提示用户输入三条线段的长度  
    scanf("%d %d %d", &a, &b, &c);  
  
    // 检查是否满足三角形的三边关系定理  
    if (a + b > c && a + c > b && b + c > a) {  
        printf("yes\n");  
    } else {  
        printf("no\n");  
    }  
  
    return 0;  
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值