PTA ( 降价提醒机器人)(查验身份证)(换硬币)

(1)#include <stdio.h>
int main()
{
    int n,m,i;
    double p[2023];
    scanf("%d %d",&n,&m);
    for(i=0; i<n; i++)
    {
        scanf("%lf\",&p[i]);
        if(p[i]<m*1.0)
        {
            printf("On Sale! %.1lf",p[i]);
            printf("\n");
        }
    }
    return 0;
}

(2)

#include <stdio.h>
#include <stdbool.h>

// 计算身份证号码的校验码
char calculate_check_code(char id[17]) {
    int weights[17] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
    char check_codes[11] = "10X98765432";
    int sum = 0;
    for (int i = 0; i < 17; i++) {
        sum += (id[i] - '0') * weights[i];
    }
    return check_codes[sum % 11];
}

// 验证身份证号码的有效性
bool validate_id(char id[18]) {
    for (int i = 0; i < 17; i++) {
        if (id[i] < '0' || id[i] > '9') {
            return false;
        }
    }
    char check_code = calculate_check_code(id);
    return check_code == id[17];
}

int main() {
    int n;
    scanf("%d", &n);
    char id[18];
    bool has_error = false;
    for (int i = 0; i < n; i++) {
        scanf("%s", id);
        if (!validate_id(id)) {
            printf("%s\n", id);
            has_error = true;
        }
    }
    if (!has_error) {
        printf("All passed\n");
    }
    return 0;
}

(3)

#include <stdio.h>
int main()
{
    int fen5,fen2,fen1,total,count,x,i,j,k;
    count=0;
    scanf("%d",&x);
    if(x>8 && x<100){
        for(i=x/5;i>=1;i--){
    for(j=x/2;j>=1;j--){
        for(k=x;k>=1;k--){
            if((5*i+j*2+k)==x){
                count++;
                total=i+j+k;
                printf("fen5:%d, fen2:%d, fen1:%d, total:%d\n",i,j,k,total);
            }
        }
    }}
    printf("count = %d",count);
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

代码骑士one

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值