Blue Bridge Cup practice questions (multiples of 3)

Problem Description

Xiaolan is very interested in multiples of 3. Now he has three different numbers a, b, and c on hand. He wants to know if the sum of two of these three numbers is a multiple of 3.

For example, when a=3,b=4,c=6, you can find that the sum of a and c is a multiple of 3. For example, when a=3,b=4,c=7, there is no way to find that the sum of the two numbers is a multiple of 3.

Input format

Enter three lines, each line contains an integer, representing a, b, and c respectively.

Output format

If the sum of two numbers can be found to be a multiple of 3, output yes, otherwise output no.

Sample input 1

3
4
6

Sample output 1

yes

Sample input 2

3
4
7

Sample output 2

no

Evaluation use case scale and conventions

For all evaluation cases, 1≤a≤b≤c≤100.

operating restrictions

  • Maximum running time: 1s
  • Maximum running memory: 256M
import java.util.Scanner;
// 1:无需package
// 2: 类名必须Main, 不可修改

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int[] a=new int[3];
        int ans=0;
        for(int i=0;i<3;i++){
          a[i]=scan.nextInt();
        }
        for(int i=0;i<3;i++){
          for(int j=i+1;j<3;j++){
            if((a[i]+a[j])%3==0){
              ans++;
            }
          }
        }
        if(ans>0){
          System.out.printf("yes");
        }
        else{
          System.out.printf("no");
        }
        scan.close();
    }
}

Guess you like

Origin blog.csdn.net/s44Sc21/article/details/132747237