CSP 201912-1 报数

import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            int num = in.nextInt();
            int n[] = new int [4];
            for(int x : n){
                x = 0;
            }
            int count=0;
            int a = 0;
            do {
                a++;
                if(a%7 == 0 || Integer.toString(a).contains("7")){
                    int b = a%4;
                    n[b] ++;
                }else{
                    count++;
                }
            }while(count != num);
            System.out.println(n[1]);
            System.out.println(n[2]);
            System.out.println(n[3]);
            System.out.println(n[0]);
        }
    }

}

 

 

import java.util.Scanner;
public class test{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            int num = in.nextInt();
            int n[] = new int[4];
            int count = 0;
            int i = 0;
            while(count != num){
                i++;
                if(i % 7 == 0 || Integer.toString(i).contains("7")){
                    int b = i%4;
                    n[b]++;
                }else{
                    count++;
                }
            }
            System.out.println(n[1]);
            System.out.println(n[2]);
            System.out.println(n[3]);
            System.out.println(n[0]);
        }
    }
}

你可能感兴趣的:(leetcode)