周末搞了好久没搞出来,很不舒服。
- package 字符串操作;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.Arrays;
- /** 输入字符格式:
- * <p>
- * 大小 字符1 字符2 ...
- * <p>
- * 每两行,进行一次处理
- * <p>
- * 比如:
- * <p>
- * 2 1 3
- * <p>
- * 4 9 19 29 0
- * <p>
- * 排序后得到
- * <p>
- * 6 0 1 3 9 19 29
- * <p>
- * PS:baidu一贴,用c语言写了一天没写出来,很郁闷,字符串的处理,内存的管理烦死了
- * 于是用java写了下,1个小时内吧,哎~~~
- * @author gnuser
- *
- *
- */
- class 输入字符串对 {
- String[] r0;
- String[] r1;
- int[] result;
- public 输入字符串对(String[] r0, String[] r1) {
- super();
- this.r0 = r0;
- this.r1 = r1;
- }
- public 输入字符串对() {
- }
- /**
- * 将r0,r1合并后,转换为整形数组
- */
- public void changeMig() {
- int[] s = new int[r0.length + r1.length];
- for(int i=0; i<r0.length; i++)
- {
- s[i] = Integer.parseInt(r0[i]);
- }
- for(int i=0; i<r1.length; i++)
- {
- s[r0.length+i] = Integer.parseInt(r1[i]);
- }
- this.setResult(s);
- }
- /**
- * 排序后打印
- */
- public void printSorted() {
- int[] rs = this.getResult();
- Arrays.sort(rs);
- System.out.print(rs.length + " ");
- for(int i=0; i<rs.length; i++)
- System.out.print(rs[i] + " ");
- System.out.println();
- }
- public String[] getR0() {
- return r0;
- }
- public void setR0(String[] r0) {
- this.r0 = r0;
- }
- public String[] getR1() {
- return r1;
- }
- public void setR1(String[] r1) {
- this.r1 = r1;
- }
- public int[] getResult() {
- return result;
- }
- public void setResult(int[] result) {
- this.result = result;
- }
- }
- public class 分割_排序_输入 {
- 输入字符串对 ip;
- public 输入字符串对 getIp() {
- return ip;
- }
- public void setIp(输入字符串对 ip) {
- this.ip = ip;
- }
- public 分割_排序_输入() {
- super();
- ip = new 输入字符串对();
- }
- public void BOBO() throws IOException
- {
- BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
- String s;
- String[] r0 = null,r1 = null;
- int row = 0;
- while((s = stdin.readLine()) != null && s.length() != 0)
- {
- if(s.trim().equals("q"))
- break;
- if((row++) % 2 == 0)
- r0 = s.substring(2).split(" ");
- else
- {
- r1 = s.substring(2).split(" ");
- ip.setR0(r0);
- ip.setR1(r1);
- ip.changeMig();
- ip.printSorted();
- }
- }
- }
- /**
- * @param args
- * @throws IOException
- */
- public static void main(String[] args) throws IOException {
- 分割_排序_输入 fps = new 分割_排序_输入();
- fps.BOBO();
- }
- }