美团面试题---时间到了没写完系列

问题描述:
//首先输入一个整数n,表示你要接下来输入的记录条数,接着输入n条记录。
//输入:4
//     math 100 90
//     algrom 50 49
//      string 20 6
//      dp    52 10
输出:
    
 algrom 5
 dp     3
 math 5
 string 3
//如上按字典序输出上面的字符串,并输出相应的级别
例如 math 100 90 x=100,y=90; x代表提交率,y代表 通过率; y/x<=30% 则难度对应级别为5 y/x<=60% 则难度对应级别为4
y/x<=100% 则难度对应级别为3
#include<cstdio>  
#include<cstring>  
#include<algorithm>  
using namespace std;   
struct node  
{  
    char st[1000]; 
	int x;
	int y; 
}a[100000];  
//字典序 此处利用c++类库的sort方法 排字典序
bool cmp(node s1,node s2)  
{  
    return strcmp(s1.st,s2.st)<0;   
}  
/*bool cmp1(node s1,node s2)  
{  
    return strcmp(s1.st,s2.st)>0;  
}  */ 
int jibie(int x,int y){  //判断改题目的难度级别
	float asa= y*1.0/(x*1.0);
	if(asa<=0.3) return 5;
	else if(asa<=0.6)return 4;
	else return 3;
}
int main()  
{  
    int n,i=0;  
    scanf("%d",&n);
    int m=n;
    while(n--){  
            
            scanf("%s%d%d",a[i].st,&a[i].x,&a[i].y);  
             i++;
	} 
        sort(a,a+m,cmp);    //利用sort库函数,排序所有 
        for(int i=0;i<m;i++) printf("%s %d\n",a[i].st,jibie(a[i].x,a[i].y));  
        
 
    return 0;  
}  

猜你喜欢

转载自blog.csdn.net/sinat_33472635/article/details/79661044