【CSP】201912-1 报数

试题编号: 201912-1
试题名称: 报数
时间限制: 1.0s
内存限制: 512.0MB

需要注意的细节:
在这里插入图片描述
在这里插入图片描述

#include <bits/stdc++.h>
using namespace std;
bool check7(int x)
{
if (x % 7 == 0)//检查是否为7的倍数
return true;
while (x)//检查是否含有7
{
if (x % 10 == 7)
return true;
x /= 10;
}
return false;
}
int main()
{
int n, cnta = 0, cntb = 0, cntc = 0, cntd = 0, cnt = 0;
cin >> n;
int i = 1;
while (cnt < n)
{
if (check7(i))//如果含有7或者是7的倍数,则跳过,判断谁跳过了这个数
{
if (i % 4 == 1)
cnta++;
else if (i % 4 == 2)
cntb++;
else if (i % 4 == 3)
cntc++;
else
cntd++;
i++;
continue;
}
i++;
cnt++;//记录没有跳过的数 的个数
}
cout << cnta << endl
<< cntb << endl
<< cntc << endl
<< cntd << endl;
return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值