HDOJ-ACM1014(JAVA)

时间:2022-05-22 22:46:58

HDOJ-ACM1014(JAVA)

这道题题意:

  求最大公约数,最大公约数是1,则GOOD,否则BAD

注意:

  输出时,如果是System.out.printf("%10d%10d    Good Choice\n\n",step,mod);会报Presentation Error。

    AC的输出是:

      System.out.printf("%10d%10d Good Choice",step,mod);
      System.out.println();
      System.out.println();

  别问我为什么,我也不知道,苦笑~

以下是java代码:

import java.util.*;

import java.io.*;

public class Main{

    public static void main(String[] arg){
Scanner scan = new Scanner(new BufferedInputStream(System.in));
int step,mod;
while(scan.hasNextInt()){
step = scan.nextInt();
mod = scan.nextInt();
if(getGCD(step,mod)==1){
System.out.printf("%10d%10d Good Choice",step,mod);
System.out.println();
System.out.println();
}else{
System.out.printf("%10d%10d Bad Choice",step,mod);
System.out.println();
System.out.println();
}
}
scan.close();
} static int getGCD(int small,int big){//求出最大公约数-->辗转相除法
int temp = small;
while((temp = big%small)!=0){
big = small;
small = temp;
}
return small;
}
}