您的位置:首页 > 其它

No.1969 Count on Canton (ACM)

2008-11-06 22:15 239 查看
import java.io.*;

public class Main
{
 String result = "";
 int term =0,x=1,y=1;
 public void find(int sum,int temp)
 {
  sum += ++temp;
  if(sum<term) find(sum,temp);
  else
  { //System.out.println("temp: "+temp+"   sum :"+sum);
   result = "";
   if(temp%2==0){
           
    x=temp;y=1;  
           for(int i=sum;i>term;i--)
    {
     x--;
     y++;
    }
    result += ((Integer)x).toString()+"/"+((Integer)y).toString();
      
   }else{
   
    x=1;y=temp;  
           for(int i=sum;i>term;i--)
    {
     x++;
     y--;
    }
    result = ((Integer)x).toString()+"/"+((Integer)y).toString();
   }
  }
 }
 public void readFile()throws Exception
 {
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  String str = "start";
  while(true){
   str = br.readLine();
   if(str.equals("")) break;
   term = Integer.parseInt(str);
   find(1,1);
   System.out.println("TERM "+term+" IS "+result);
  }
  
 }
 public static void main(String args[])throws Exception
 {
  new Main().readFile();
 }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息