PKU_ACM_1658_Eva's Problem

 http://acm.pku.edu.cn/JudgeOnline/problem?id=1658  原题

 

超级无聊的题

 

  1. import java.io.*;
  2. import java.util.*;
  3. public class Main
  4. {
  5.     static Vector<String> data = new Vector<String>();
  6.     public static void main(String[] args) throws Exception
  7.     {
  8.         readFile();
  9.         process();
  10.     }
  11.         
  12.     public static void readFile() throws Exception
  13.     {
  14.         BufferedReader br = new BufferedReader(
  15.             new InputStreamReader(System.in));
  16.         int num = Integer.valueOf(br.readLine());
  17.         int iCount = 0;
  18.         while(iCount<num)
  19.         {
  20.             data.add(br.readLine());
  21.             iCount++;
  22.         }
  23.         br.close(); 
  24.     }
  25.     public static void process()
  26.     {
  27.         int iCount = 0;
  28.         StringTokenizer st = null;
  29.         int[] arrays = null;
  30.         while(iCount<data.size())
  31.         {
  32.             if(iCount!=0)
  33.                 System.out.println();
  34.             st = new StringTokenizer(data.get(iCount)," ");
  35.             arrays = new int[st.countTokens()];
  36.             int i = 0;
  37.             while(st.hasMoreTokens())
  38.             {
  39.                 arrays[i++] = Integer.valueOf(st.nextToken());
  40.             }
  41.             
  42.             int temp = 0;
  43.             boolean bFlag = true;
  44.             for(int j=0; j<arrays.length-1; j++)
  45.             {
  46.                 if(arrays[j+1]-arrays[j]==temp || temp==0)
  47.                     temp = arrays[j+1]-arrays[j];
  48.                 else
  49.                 {
  50.                     bFlag = false;
  51.                 }
  52.             }
  53.             if(bFlag)
  54.             {
  55.                 temp = arrays[arrays.length-1] + temp;
  56.             }
  57.             else
  58.             {
  59.                 temp = arrays[arrays.length-1] *
  60.                     (arrays[arrays.length-1]/arrays[arrays.length-2]);
  61.             }
  62.             
  63.             for(int j=0; j<arrays.length; j++)
  64.             {
  65.                 if(j!=0)
  66.                     System.out.print(" ");
  67.                 System.out.print(arrays[j]);
  68.             }
  69.             System.out.print(" "+temp);
  70.             iCount++;
  71.         }
  72.     }
  73. }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值