题:http://acm.hdu.edu.cn/showproblem.php?pid=1014看了题目,猜想题目的本质可能就是只求两数的最大公约数。
速速写出代码,一提交,结果弄了一晚上,格式错误,郁闷啊........import java.util.Scanner;public class Main { public static int getMax(int m, int n) {
int max = n > m ? n : m;
int min = m < n ? m : n;
int tmp = 0;
while (min != 0) {
tmp = max % min;
max = min;
min = tmp;
}
return max;
} public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int step;
int mod;
while (cin.hasNextInt()) {
step = cin.nextInt();
mod = cin.nextInt();
if (getMax(step, mod) == 1) {
System.out.printf("%10d%10d    Good Choice\n\n", step, mod);
} else {
System.out.printf("%10d%10d    Bad Choice\n\n", step, mod);
}
} }
}这是别人AC了的C++代码,感觉就是一样嘛!看不出哪里错了,不知道是不是\n\n这里出了问题,空格问题我检查过,没问题。
谁 给看看...谢谢!

解决方案 »

  1.   


    #include<iostream>
    #include<iomanip>
    using namespace std;int main()
    {
    int i;
    int a,b,max,min,temp;
    while(cin>>a>>b)
    {
    if(a==0&&b==0) break;
    if(a>b){max=a,min=b;}
    else {max=b,min=a;}
    while(min!=0)
    {
    temp=max%min;
    max=min;
    min=temp;
    }
    if(max==1)  cout<<setiosflags(ios::right)<<setw(10)<<a<<setiosflags(ios::right)<<setw(10)<<b<<"    Good Choice"<<endl<<endl;       
    else      cout<<setiosflags(ios::right)<<setw(10)<<a<<setiosflags(ios::right)<<setw(10)<<b<<"    Bad Choice"<<endl<<endl;

        }
        
    return 0;

    }
      

  2.   

    //~~~~
                mod = cin.nextInt();
                try {
                    Thread.sleep(100);///////////
                } catch (InterruptedException ex) {
                }
                if (getMax(step, mod) == 1) {
      

  3.   

    解决了。问题同在换行上。
    AC的代码;import java.io.IOException;
    import java.util.Scanner;public class Main { public static int getMax(int m, int n) {
    int max = n > m ? n : m;
    int min = m < n ? m : n;
    int tmp = 0;
    while (min != 0) {
    tmp = max % min;
    max = min;
    min = tmp;
    }
    return max;
    } public static void main(String[] args) throws IOException {
    Scanner cin = new Scanner(System.in);
    int step;
    int mod;
    while (cin.hasNextInt()) {
    step = cin.nextInt();
    mod = cin.nextInt();
    if (getMax(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();
    }
    } }
    }航电的系统不支持\n,搞不懂为什么
      

  4.   

    System.out.printf 中可以使用 %n 进行换行