爱奇艺2018秋季校招java工程师(第二场)

字符串价值-AC(最笨的办法居然AC)
package iQIYI.QiuZhao2017_2.ValueOfString;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

/**
 * Created by tzy on 2017/10/14.
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in );
        while (sc.hasNext()) {
            String str = sc.nextLine();
            int num = Integer.parseInt(sc.nextLine());
            List<Temp> list = new LinkedList<Temp>();
            char[] chars = new char[127];
            for (int i = 0; i < str.length(); i++) {
                char ch = str.charAt(i);
                chars[ch]++;
            }
            for (int i = 0; i < chars.length; i++) {
                if (chars[i] != 0) {
                    Temp t = new Temp(String.valueOf(i).charAt(0), chars[i]);
                    list.add(t);
                }
            }
            Collections.sort(list);
            while (num > 0) {
                list.get(0).count--;
                num--;
                Collections.sort(list);
            }
            int res = 0;
            for (int i = 0; i < list.size(); i++) {
                res += list.get(i).getCount() * list.get(i).getCount();
            }
            System.out.println(res);
        }
    }
}

class Temp implements Comparable<Temp> {
    Character ch;
    int count;

    public int compareTo(Temp o) {
        return o.count - this.count;
    }

    public char getCh() {
        return ch;
    }

    public void setCh(char ch) {
        this.ch = ch;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public Temp(char ch, int count) {

        this.ch = ch;
        this.count = count;
    }
}
第二题博弈论~~不会
第三题~~~就是考大数类,妈的又一次载在了大数类,上次滴滴就是,我还能说啥~~没有提交。不过感觉没有错
package iQIYI.QiuZhao2017_2.sdf;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner;

/**
 * Created by tzy on 2017/10/14.
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        while (scanner.hasNext()){
            int n=scanner.nextInt();
            int m=scanner.nextInt();
            System.out.println(getExp(n,m));
        }
    }
    public static BigDecimal getExp(int n,int m){
        BigInteger total=combination(m+n,2);
        BigInteger num=combination(m,2);
        int temp=n*m;
        BigInteger num1=new BigInteger(String.valueOf(temp));
        BigInteger sum=num.add(num1);
        BigDecimal total0=new BigDecimal(total);
        BigDecimal sum0=new BigDecimal(sum);
        return total0.divide(sum0,1,BigDecimal.ROUND_UP);
    }

    public static BigInteger combination(int n, int m) {
        BigInteger big_m=factorial(m);
        BigInteger big_n=factorial(n);
        BigInteger big_n_m=factorial(n-m);

        BigInteger result=big_n.divide(big_n_m);
        result=result.divide(big_m);
        return (n >= m) ? result : new BigInteger("0");
    }
    private static BigInteger factorial(int n) {
        BigInteger result=new BigInteger("1");
        for (int i = 1; i <=n ; i++) {
            result=result.multiply(new BigInteger(String.valueOf(i)));
        }
        return result;
    }
}

#爱奇艺#
全部评论
import java.util.*; public class Main {         public static void main(String[] args) {                 Scanner in = new Scanner(System.in);                 int t = in.nextInt();                 int[] org = new int[t];                 for(int i = 0;i < t;i++) {                         org[i] = in.nextInt();                     }                String s = null;                     for(int j:org) {                             if(j%5==0) s="yang";                             else if(j%5==1) s="niu";                             else if(j%5==2) s="yang";                             else if(j%5==3) s="niu";                             else s="niu";                                 System.out.println(s);                 }     } } 这是青草问题 import java.util.*; public class Main {     public static void main(String[] args) {         Scanner in = new Scanner(System.in);         String s = in.next();         int k = in.nextInt();         int[] mark = new int[26];         for(int i = 0;i < s.length();i++) {             mark[s.charAt(i)-'a']++;         }         Arrays.sort(mark);         for(int i = 0;i < k;i++) {             mark[0]--;             Arrays.sort(mark);         }                  int count =0;         for(int res:mark) {             if(res !=0)                 count = count+res*res;         }         System.out.println(count);     } } 字符串价值
点赞 回复
分享
发布于 2017-10-14 21:40
又挂了~~~
点赞 回复
分享
发布于 2017-10-14 21:38
联易融
校招火热招聘中
官网直投
第三题不是数学期望吗?
点赞 回复
分享
发布于 2017-10-14 21:59

相关推荐

点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务