試題描述
試題代碼
package com.hym.PAT_B;
import java.util.Scanner;
/**
* Created by ymhou on 2016/11/21.
*通過全部測(cè)試點(diǎn)传惠,答案正確
*/
public class PAT_B_1010 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String line = scanner.nextLine();
String numArray[] = line.split("\\s+");
if(numArray.length==2 && numArray[1].equals("0")){
System.out.print("0 0");
}else {
String outstring="";
for(int i=0; i<numArray.length; i=i+2){
int a = Integer.parseInt(numArray[i])*Integer.parseInt(numArray[i+1]);
int b = Integer.parseInt(numArray[i+1])-1;
if(a==0) continue;
outstring = outstring+a+" "+b+" ";
}
System.out.print(outstring.substring(0,outstring.length()-1));
}
}
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者