首页 > 代码库 > 网易前端笔试第二题2017

网易前端笔试第二题2017

import java.util.*;/*把并列的两个整数(中间用空格隔开)倒转,并去掉开头的0,然后将两个结果合起来再倒转,去0; * 输入:123 234 * 输出:234123 * 输入:10020 123 * 输出: 1231002*/public class daozhuan {    public static void main(String[] args){        Scanner cin = new Scanner(System.in);        String str = cin.nextLine();        String[] st = str.split(" ");        char[] s = st[0].toCharArray();        char[] t = st[1].toCharArray();        char[] a = rev(s);        char[] b = rev(t);        List<Character> list = clear(a);        List<Character> list1 = clear(b);        /*for(char i:list){            System.out.print(i);        }*/        /*for(int i=0;i<list.size();i++){            System.out.print(list.get(i));        }*/        char[] result = new char[list.size()+list1.size()];        for(int i=0;i<result.length;i++){            if(i<list.size()){                result[i]=list.get(i);            }else{                result[i]=list1.get(i-list.size());            }        }        result = rev(result);        for(int i=0;i<result.length;i++){            System.out.print(result[i]);        }            }    public static ArrayList<Character> clear(char[] s){        ArrayList<Character> list = new ArrayList<Character>();        int flag=0;                for(int i=0;i<s.length;i++){            if(s[i]!=48){                flag=i;                break;            }        }        for(int i=flag;i<s.length;i++){            list.add(s[i]);        }                return list;    }    public static char[] rev(char[] s){        char temp=0;        int len = s.length-1;        for(int i=0;i<=len/2;i++){            temp=s[i];            s[i]=s[len-i];            s[len-i]=temp;        }                return s;    }}

 

网易前端笔试第二题2017