一、题目
二、拆分数字
#include <iostream>
using namespace std;
void breakNumber(int num)
{
while (num > 10) {
int digit = num % 10;
num = num / 10;
cout << digit << endl;
}
cout << num << endl;
}
int main()
{
breakNumber(123456789);
return 0;
}
输出:
9
8
7
6
5
4
3
2
1
三、代码
#include <iostream>
using namespace std;
//记录四个人各跳了几次
//skip[0] - 丁
//skip[1] - 甲
//skip[2] - 乙
//skip[3] - 丙
int skip[4] = { 0,0,0,0 };
int n;
int cnt = 0;
bool containSeven(int num)
{
while (num > 10) {
int digit = num % 10;
num = num / 10;
if (digit == 7)
return true;
}
if (num == 7)
return true;
else
return false;
}
int main()
{
cin >> n;
for (int num = 1; ; num++) {
if (num % 7 == 0 || containSeven(num))
skip[num % 4]++;
else
cnt++;
if (cnt == n)
break;
}
cout << skip[1] << endl;
cout << skip[2] << endl;
cout << skip[3] << endl;
cout << skip[0] << endl;
return 0;
}