1.报数
甲乙丙丁决定玩一个报数的游戏来打发时间。游戏规则为四个人从1开始轮流进行报数,但如果需要报出的数是7的倍数或含有数字7则直接跳过。
此外大家约定,在总共报出了n个数后(不计入被跳过的数)游戏结束。现在需要你来帮忙统计,游戏过程中每个人各自跳过了几次。
输入
从标准输入读入数据。
输入仅一行,包含一个正整数n,表示报出了多少个数后游戏结束。
输出
输出到标准输出。
输出共四行,每行一个整数,依次表示甲乙丙丁四人在游戏过程中跳过的次数。
输入样例1
20
输出样例1
2
1
1
0
样例解释1
报数过程为:
甲:1,乙:2,丙:3,丁:4
甲:5,乙:6,丙:跳过,丁:8
甲:9,乙:10,丙:11,丁:12
甲:13,乙:跳过,丙:15,丁:16
甲:跳过,乙:18,:19,丁:20
甲:跳过,乙:22,丙:23,丁:24
在丁报出24后,四个人总计报出了20个数,游戏结束。
输入样例2
66
输出样例2
7
5
11
5
public class Num {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int n=scanner.nextInt();
int []a=solve(n);
for(int i=0;i<4;i++){
System.out.println(a[i]);
}
}
public static int[] solve(int n){
int[]a=new int[4];
int start=0;
int count=1;
while(count<=n){
if(judge(count)){
start=count%4;
switch (start) {
case 0:
start=4;
break;
case 1:
start=0;
break;
case 2:
start=1;
break;
case 3:
start = 2;
break;
}
a[start]++;
n=n+1;
}
count++;
}
return a;
}
//judge用来判断该轮到甲乙丙丁谁了,有两种情况
public static boolean judge(int n){
//第一种情况是7的倍数
if(n%7==0)return true;
while(n!=0)
{
if(n%10==7)//含有数字7
return true;
n/=10;
}
return false;
}
}