andy6804tw
7/15/2016 - 10:57 AM

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=12&problem=976&mosmsg=Submission+received+w

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=12&problem=976&mosmsg=Submission+received+with+ID+17606158 困難度 ★ 這題方法就是把每個位數拆開做相加並且加上前一個進位數,這題要注意的是兩個位數可能不相同所以不是合用字串切割作法

import java.util.Scanner;
public class Main {
 
 public static void main(String[] args) {
  Scanner scn=new Scanner(System.in);
   
  while(scn.hasNext()){
   int tot=0,count=0,num=0,a=scn.nextInt(),b=scn.nextInt();
   if(a==0&&b==0)break;
   while(a!=0||b!=0){
    num=(a%10+b%10+num)/10;
    if(num!=0)
    count++;a/=10;b/=10;
   }
     
   if(count==0)
    System.out.println("No carry operation.");
   else
    System.out.printf("%d carry %s\n",count,count&gt1?"operations.":"operation.");
    
  }
 
 }
 /* 
    題目:Q10035 - Primary Arithmetic
    作者:1010
    時間:西元 2016 年 7 月 */
 
}