首页 > 试题广场 >

题目列表

[编程题]题目列表
  • 热度指数:1883 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
    小明同学收集了 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
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

struct Question
{
    string name;
    int X;
    int Y;
    int H;
};

bool compare(Question a,Question b)
{
    return a.name<b.name;
}

int main()
{
    int n;
    cin>>n;
    vector<Question> questions(n);
    for(int i=0;i<n;i++)
    {
        cin>>questions[i].name>>questions[i].X>>questions[i].Y;
        float pass=questions[i].Y/(float)questions[i].X;
        if(pass>=0&&pass<=0.3f)
        {
            questions[i].H=5;
        }
        else if(pass>0.3f&&pass<=0.6f)
        {
            questions[i].H=4;
        }
        else
        {
            questions[i].H=3;
        }
    }
    
    sort(questions.begin(),questions.end(),compare);
    
    for(int i=0;i<n;i++)
    {
        cout<<questions[i].name<<" "<<questions[i].H<<endl;
    }
    return 0;
}

发表于 2019-04-03 16:37:48 回复(0)
更多回答

python解法

arr = []
for i in range(int(input())):
    a, b, c = input().split()
    if 0.6 < int(c) / int(b):
        difficulty = "3"
    elif int(c) / int(b) <= 0.3:
        difficulty = "5"
    else:
        difficulty = "4"
    arr.append(a + " " + difficulty)

for i in sorted(arr):
    print(i)
编辑于 2019-02-24 19:46:16 回复(0)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.TreeMap;

/**
 * @author wylu
 */
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());

        TreeMap<String, Integer> map = new TreeMap<>();
        for (int i = 0; i < n; i++) {
            String[] strs = br.readLine().split(" ");
            int x = Integer.parseInt(strs[1]), y = Integer.parseInt(strs[2]);
            double rate = 1.0 * y / x;
            if (rate <= 0.3) map.put(strs[0], 5);
            else if (rate <= 0.6) map.put(strs[0], 4);
            else map.put(strs[0], 3);
        }

        for (Map.Entry<String, Integer> entry : map.entrySet()) {
            System.out.println(entry.getKey() + " " + entry.getValue());
        }
    }
}

发表于 2019-03-13 16:47:30 回复(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)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
int main()
{
    int n;
    cin>>n;
    set<string> s;
    for(int i=1;i<=n;i++)
    {
        string str;
        double x,y,d;
        cin>>str>>x>>y;
        d=y/x;
        if(d<=0.3)
        {
            str+=" 5";
            s.insert(str);
            continue;
        }
        else if(d>0.3&&d<=0.6)
        {
            str+=" 4";
            s.insert(str);
            continue;
        }
        else
        {
            str+=" 3";
            s.insert(str);
            continue;
        }
    }
用set结合字符串比较简单
发表于 2019-04-17 14:49:25 回复(0)
#include <bits/stdc++.h>

using namespace std;

struct C{     string name;     int s;
};

bool cmp(C a, C b){     return a.name < b.name;
}

int main()
{     int n,x,y;     cin>>n;     C a[n];     for(int i=0;i<n;i++){         cin>>a[i].name>>x>>y;         if(1.0*y/x>0.6)             a[i].s = 3;         else if(1.0*y/x>0.3)             a[i].s = 4;         else             a[i].s = 5;     }     sort(a,a+n,cmp);     for(int i=0;i<n;i++)         cout<<a[i].name<<" "<<a[i].s<<endl;     return 0;
}

发表于 2019-02-19 03:18:23 回复(0)
n = int(input())
res = []
for i in range(n):
    name, a, b = input().split()
    h = int(b)/int(a)
    if h <= 0.3:
        res.append(name + " " + str(5))  # 采用字符串拼接的方式,降低了list的维度,方便了sorted
    elif h > 0.3 and h <= 0.6:
        res.append(name + " " + str(4))
    else:
        res.append(name + " " + str(3))
for t in sorted(res):
    print(t)

发表于 2019-03-21 10:11:59 回复(0)
思路:定义一个结构体存放数据,排序输出就好
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

struct pro
{
    string name;
    float X;
    float Y;
};

bool cmp(pro a,pro b)
{
    return a.name<b.name;
}
int main()
{
    pro p[100];
    int num;
    cin>>num;
    for(int i=0;i<num;i++)
    {
        cin>>p[i].name;
        cin>>p[i].X;
        cin>>p[i].Y;
    }
    
    sort(p,p+num,cmp);
    
    for(int i=0;i<num;i++)
    {
        cout<<p[i].name<<' ';
        float res=p[i].Y/p[i].X;
        if(0<=res&&res<=0.3)
        {
            cout<<'5'<<endl;
        }
        else if(0.3<=res&&res<=0.6)
        {
            cout<<'4'<<endl;
        }
        else
        {
            cout<<'3'<<endl;
        }
    }
    return 0;
}

发表于 2019-06-21 11:23:56 回复(0)
const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void async function () {
    // Write your code here
    await readline()
    let arr=[]
    while(line = await readline()){
        arr.push(line)
    }
    arr.sort()
   
    arr.forEach(v=>{
        let array=v.split(' ')
        if(array[2]/array[1]>=0&&array[2]/array[1]<=0.3){
            array=[array[0],5]
        }else if(array[2]/array[1]>0.3&&array[2]/array[1]<=0.6){
            array=[array[0],4]
        }else{
           array=[array[0],3]
        }
        console.log(array.join(' '))
    })

}()
发表于 2024-01-05 10:53:00 回复(0)
package main

import (
    "fmt"
    "sort"
)

type Item struct{
    name string
    rate int
}

func main() {
    var n int
    fmt.Scan(&n)
    var name string
    var x,y float64
    arr:=make([]*Item,n)
    for i:=0;i<n;i++{
        fmt.Scan(&name,&x,&y)
        arr[i]=&Item{name,check(x,y)}
    }
    sort.Slice(arr,func(i,j int)bool{
        return arr[i].name<arr[j].name
    })
    for _,it:=range arr{
        fmt.Printf("%v %v\n",it.name,it.rate)
    }
}

func check(x,y float64)int{
    if y/x<=0.3{
        return 5
    }else if y/x<=0.6{
        return 4
    }
    return 3
}

发表于 2023-03-18 09:18:33 回复(0)
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)
#include<bits/stdc++.h>

using namespace std;

int main()
{
	int z;
	cin >> z;
	map<string, int> msi;
	map<string, int> ::iterator  it;
	while (z--)
	{
		string s;
		cin >> s;
		float x, c;
		int v;
		cin >> x >> c;
		float f = c / x;
		if (f >= 0 && f <= 0.3)v = 5;
		else if (f > 0.3 && f <= 0.6)v = 4;
		else v = 3;
		msi[s] = v;
	}
	for (it = msi.begin(); it != msi.end(); it++)cout << it->first << " " << it->second << endl;
}

发表于 2020-04-11 14:23:41 回复(0)
#include<iostream>
#include<map>
using namespace std;
int main()
{
    int N;
    cin>>N;
    map<string,int> total;
    string temp;
    float temp1,temp2;
    for(int i=0;i<N;i++)
    {
        cin>>temp;
        cin>>temp1>>temp2;
        if(0<=(temp2/temp1)&&(temp2/temp1)<=0.3) total[temp]=5;
        else if(0.3<(temp2/temp1)&&(temp2/temp1)<=0.6) total[temp]=4;
        else total[temp]=3;
    }
    for(auto s:total)
    {
        cout<<s.first<<' '<<s.second<<endl;
    }
}

发表于 2019-09-10 22:52:15 回复(0)

纯净的C语言
#include <stdio.h>
#include <string.h>

#define MAXN 110

int n;
char s[MAXN][MAXN];
int nd[MAXN];
int used[MAXN];

int nandu(int x,int y);

int main()
{
	int i,j,t1,t2,min;
	scanf("%d",&n);
	getchar();
	for(i=0;i<n;i++)
	{
		scanf("%s%d%d",s[i],&t1,&t2);
		getchar();
		nd[i] = nandu(t1,t2);
	}
	for(i=0;i<n;i++)
	{
		for(min=0;used[min];min++);
		for(j=min+1;j<n;j++)
			if(!used[j] && strcmp(s[j],s[min])<0)
				min = j;
		for(j=0;s[min][j];j++)
			putchar(s[min][j]);
		printf(" %d\n",nd[min]);
		used[min] = 1;
	}
	return 0;
}

int nandu(int x,int y)
{
	double t;
	t = (double)y / (double)x;
	if(t>0.6)
		return 3;
	if(t>0.3)
		return 4;
	return 5;
}

发表于 2019-08-19 17:37:42 回复(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)
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct Topic
{
    char Name[101];
    unsigned char Difficult;
};

int cmdfun(const void *p, const void *q)
{
    return(strcmp((char *)p, (char *)q));
}

int main(void)
{
    int x, y;
    float dcl;
    Topic *topic = NULL;
    int i, n;
    scanf("%d",&n);
    topic = (Topic *)malloc(n*sizeof(Topic));
    for(i=0; i<n; i++)
    {
        scanf("%s%d%d",(char *)&topic[i].Name, &x, &y);
        dcl = 1.0 * y / x;
        if(dcl <= 0.3)
        {
            topic[i].Difficult = 5;
        }
        else if(dcl <= 0.6)
        {
            topic[i].Difficult = 4;
        }
        else if(dcl <= 1)
        {
            topic[i].Difficult = 3;
        }       
    }
    qsort(topic[0].Name, n, sizeof(Topic), cmdfun);
    for(i=0; i<n; i++)
    {
        printf("%s %d\n",topic[i].Name,topic[i].Difficult);
    }
    return 0;
}

发表于 2019-05-04 22:19:22 回复(0)
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        TreeSet<Entity> treeSet = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            treeSet.add(new Entity(scanner.next(), scanner.nextInt(), scanner.nextInt()));
        }
        for (Entity entity : treeSet) {
            System.out.println(entity);
        }
    }

    public static class Entity implements Comparable<Entity> {
        String name;
        int range = 0;

        public Entity(String name, int x, int y) {
            this.name = name;
            double z = ((double) y) / x;
            if (z >= 0 && z <= 0.3) {
                range = 5;
            } else if (z > 0.3 && z <= 0.6) {
                range = 4;
            } else if (z > 0.6 && z <= 1) {
                range = 3;
            }
        }

        @Override
        public String toString() {
            return this.name + " " + this.range;
        }

        @Override
        public int compareTo(Entity o) {
            return name.compareTo(o.name);
        }
    }
}
发表于 2019-04-03 11:04:02 回复(0)
n = int(input())
ans = []
for _ in range(n):
    name, X, Y = input().split()
    X = int(X)
    Y = int(Y)
    if(Y * 1.0 / X <= 0.3):
        level = 5
    elif(Y * 1.0 / X > 0.3 and Y * 1.0 / X <= 0.6):
        level = 4
    else:
        level = 3
    ans.append([name, level])
ans.sort(key = lambda x: x[0])
for t in ans:
    print(t[0], t[1])

发表于 2019-03-28 21:51:56 回复(0)
def main():
    n = int(input())
    aDict = dict() for i in range(n):
        aList = input().split()
        name = aList[0]
        X = int(aList[1])
        Y = int(aList[2])
        aDict[name] = [X,Y] for j in sorted(aDict.keys()):
        bList = []
        bList.append(j)
        hard_num = aDict[j][1] / aDict[j][0] if 0 <= hard_num <= 0.3:
            hard = 5  if 0.3 < hard_num <= 0.6:
            hard = 4  if 0.6 < hard_num <= 1:
            hard = 3  bList.append(str(hard)) print(' '.join(bList)) if __name__ == '__main__':
    main()

发表于 2019-02-26 19:51:40 回复(0)

问题信息

难度:
19条回答 2766浏览

热门推荐

通过挑战的用户

查看代码