Zenoti SDE-面试经历(4)


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Zenoti {

    /*Zenoti dotnet software engineer*/

    /*Online test : Status pass*/

        public static void main1(String args[] ) throws Exception {
            Scanner sc=new Scanner(System.in);
            int n=sc.nextInt();
            while(n > 0){
                String str=sc.next();
                Map fhMap=new LinkedHashMap<>();

                for(char ch : str.toCharArray()){
                    fhMap.put(ch, fhMap.getOrDefault(ch,0)+1);
                }

                StringBuilder sb=new StringBuilder();
                for(char ch : fhMap.keySet()){
                    sb.append(ch);
                    sb.append(fhMap.get(ch));
                }
                System.out.println(sb);
                n--;
            }

        }


    public static void main2(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter wr = new Prin

tWriter(System.out); String S = br.readLine(); String[] out_ = tokenize_string(S); for (int i_out_ = 0; i_out_ < out_.length; i_out_++) { System.out.println(out_[i_out_]); } wr.close(); br.close(); } static String[] tokenize_string(String S){ char[] chr= S.toCharArray(); int f=-1; List str=new ArrayList<>(); StringBuilder sb=new StringBuilder(); for(int i=0;i0){ String str=sc.next(); StringBuilder sb=new StringBuilder(); for(char ch : str.toCharArray()){ if(ch >=65 && ch <=90){ if(sb.length()!=0) sb.append('_'); sb.append((char) (ch+32)); }else{ sb.append(ch); } } System.out.println(sb.toString()); n--; } } /*[19/04/2024] Interview questions on hacker earth : status pass*/ /** * 1 * 1 2 1 * 1 2 3 2 1 * 1 2 3 4 2 3 1 */ /*Time : O(N^2) Space :O(1)*/ public static void printPattern(int n) { for(int i=0;i<=n;i++) { int k=n-i; while(k-->0) System.out.print(" "); for (int j = 1; j <= i; j++) System.out.print(j +" "); for (int j = i-1; j >0; j--) System.out.print(j +" "); System.out.println(); } } /*Time :O(2^n) Space :O(1) + (call stack space)*/ public int fib(int n ){ if(n<2) return 1; return fib(n-1)+fib(n-2); } /*Time :O(n) Space :O(1) + (call stack space)*/ public int fibMemo(int n, Map memo){ if(n<2) return 1; if(memo.containsKey(n)) return memo.get(n); memo.put(n, fib(n-1)+fib(n-2)); return memo.get(n); } /*Time : O(n) Space :O(n)*/ public int fibTab(int n){ if(n<2) return 1; int[] dp =new int[n+1]; for(int i=2;ifMax){ sMax=fMax; fMax=i; }else sMax=Math.max(sMax,i); } System.out.println(fMax +" , "+sMax); } public boolean isAnagram(String s, String t){ int[] asciiArr=new int[256]; /*constraints: without using extra loops & extra hashmaps*/ if(s.length()!=t.length()) return false; for(int i=0; i0) return false; return true; } /*sql*/ }

结果:未选择