http://acm.pku.edu.cn/JudgeOnline/problem?id=1658 原题
超级无聊的题
- import java.io.*;
- import java.util.*;
- public class Main
- {
- static Vector<String> data = new Vector<String>();
- public static void main(String[] args) throws Exception
- {
- readFile();
- process();
- }
- public static void readFile() throws Exception
- {
- BufferedReader br = new BufferedReader(
- new InputStreamReader(System.in));
- int num = Integer.valueOf(br.readLine());
- int iCount = 0;
- while(iCount<num)
- {
- data.add(br.readLine());
- iCount++;
- }
- br.close();
- }
- public static void process()
- {
- int iCount = 0;
- StringTokenizer st = null;
- int[] arrays = null;
- while(iCount<data.size())
- {
- if(iCount!=0)
- System.out.println();
- st = new StringTokenizer(data.get(iCount)," ");
- arrays = new int[st.countTokens()];
- int i = 0;
- while(st.hasMoreTokens())
- {
- arrays[i++] = Integer.valueOf(st.nextToken());
- }
- int temp = 0;
- boolean bFlag = true;
- for(int j=0; j<arrays.length-1; j++)
- {
- if(arrays[j+1]-arrays[j]==temp || temp==0)
- temp = arrays[j+1]-arrays[j];
- else
- {
- bFlag = false;
- }
- }
- if(bFlag)
- {
- temp = arrays[arrays.length-1] + temp;
- }
- else
- {
- temp = arrays[arrays.length-1] *
- (arrays[arrays.length-1]/arrays[arrays.length-2]);
- }
- for(int j=0; j<arrays.length; j++)
- {
- if(j!=0)
- System.out.print(" ");
- System.out.print(arrays[j]);
- }
- System.out.print(" "+temp);
- iCount++;
- }
- }
- }