首页 > 试题广场 >

题目列表

[编程题]题目列表
  • 热度指数:1937 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
    小明同学收集了 n 道编程问题,他想做一个网站把这些题目放在上面,对于每一道问题给出问题的名称 name ,该问题的提交次数 X ,该问题的通过次数 Y。一个问题的通过率定义为 Y/X 。小明根据通过率把问题难度分了 3 个登记:
    1.通过率 ,难度为 5
    2.通过率 ,难度为 4
    3.通过率 ,难度为 3
    为了方便大家查阅题目,小明希望所有题目按照题目名称的字典序从小到大排列在网站上,并且能显示每个题目的难度,你能帮他实现吗?

数据范围: ,每个 name 的长度满足 ,name 中只有小写字母, 。保证输入的名称各不相同

输入描述:
输入一个数 n ,接下来有 n 行,每行输入一个字符串 name ,整数 X ,证书 Y ,依次表示每个题目的名称,提交次数和通过次数。


输出描述:
输出 n 行,按字典序从小到大排序后的题目,每行先输出一个字符串,题目的名称,再输出一个数,题目的难度等级用一个空格隔开。
示例1

输入

4
math 100 90
algorithm 10 8
string 50 1
dp 100 50

输出

algorithm 3
dp 4
math 3
string 5
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) {
            int num = in.nextInt();
            in.nextLine();
            Map<String,Integer> map = new TreeMap<>();
            for(int i = 0; i < num; i++){
                String[] str = in.nextLine().split(" ");
                int level = diffLevel(Integer.parseInt(str[2]),Integer.parseInt(str[1]));
                map.put(str[0],level);
            }
            for(String s : map.keySet()){
                System.out.println(s + " " + map.get(s));
            }
        }
    }
    
    public static int diffLevel(double x, double y){
        double res = x/y;
        if(res <= 0.3) return 5;
        else if(res > 0.3 && res <= 0.6) return 4;
        return 3;
    }
}

发表于 2021-02-17 22:07:43 回复(0)
为啥我的只通过80%?

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.TreeMap;

public class Main{
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        Map<String,Integer> map = new TreeMap<String,Integer>();
        for(int i =0; i < n; i++) {
            String[] str = br.readLine().split(" ");
            int a = Integer.parseInt(str[1]);
            int b = Integer.parseInt(str[2]);
            double val = (double) b / a;
            if (val >0 && val <=0.3) {
                map.put(str[0], 5);
            }else if(val > 0.3 && val <= 0.6){
                map.put(str[0], 4);
            }else {
                map.put(str[0], 3);
            }
        }
        
        for (Map.Entry<String, Integer> entry : map.entrySet()) {
            System.out.println(entry.getKey() + " " + entry.getValue());
        }
    }    
}

编辑于 2019-06-28 22:32:24 回复(0)
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        TreeMap<String, Integer> map = new TreeMap<>();
        while (n-- > 0) {
            String str = sc.next();
            double all = sc.nextInt();
            double pass = sc.nextInt();
            double passRate = pass / all;
            if (passRate >= 0 && passRate <= 0.3) {
                map.put(str, 5);
            } else if (passRate > 0.3 && passRate <= 0.6) {
                map.put(str, 4);
            } else {
                map.put(str, 3);
            }
        }
        for (Map.Entry<String, Integer> entry : map.entrySet()) {
            System.out.println(entry.getKey() + " " + entry.getValue());
        }
    }
}
发表于 2019-06-16 12:43:24 回复(0)

问题信息

难度:
3条回答 3093浏览

热门推荐

通过挑战的用户

查看代码
题目列表