• 网易前端笔试第二题2017 整数倒置,去0


    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;
        }
    }
  • 相关阅读:
    洛谷P1724 东风谷早苗
    hdu 1001 Sum Problem
    洛谷 P1006 传纸条
    codevs 6116 区间素数
    LibreOJ #101. 最大流
    洛谷 P1455 搭配购买
    LibreOJ #119. 最短路 (堆优化dijkstra)
    LibreOJ #109. 并查集
    COGS.1200 ganggang的烦恼
    uoj #15. 【NOIP2014】生活大爆炸版石头剪刀布
  • 原文地址:https://www.cnblogs.com/Janejxt/p/5866458.html
Copyright © 2020-2023  润新知