跳转至

Contest 2

比较大小
Description
输入3个整数,按照从小到大的顺序输出。试着编写相应的程序。
Input
输入三个整数。
Output
按照从小到大形式输出
Sample Input 1 
3 2 1
Sample Output 1
1 2 3
高速公路超速处罚
Description
按照规定,在高速公路上行驶的机动车,超出本车道限速的10%则处200元处罚;若超出50%,就要吊销驾驶证。请编写程序根据车速和限速自动判别对该机动车的处理。
Input
输入n和m分别对应,机动车速和本车道限速。
Output
输出出发结果,正常行驶:normal,超出(或等于)10%低于50%:200,超出(或等于)50%:revoke。
Sample Input 1 
110 100 
Sample Output 1
200
Sample Input 2 
100 100
Sample Output 2
normal
Sample Input 3 
150 100
Sample Output 3
revoke
#include <stdio.h>
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    if(10*n<15*m && 10*n>=11*m)printf("200");
    else if(10*n>=15*m)printf("revoke");
    else printf("normal");
    return 0;
}
出租车计价
Description
某城市普通出租车收费标准如下:起步里程为3公里,起步费10元,超出起步时:  3公里以上10公里以内的部分(包含十公里),每公里2元;
超过10公里以上的部分加收50%的空驶补贴费,即每公里3元;运营过程中,因路阻及乘客要求临时停车的,每5分钟2元计收(不足五分钟则不收费)。
运价计费位数四舍五入,保留到元。编写程序,输入行驶路程(公里)与等待时间(分钟),计算并输出乘客应支付费用(元)。
Input
输入double类型的两个浮点数,分别表示里程数和等待时间。
Output
输出计程车所收费用结果四舍五入。
Sample Input 1 
4.25 9.5
Sample Output 1
15
#include <stdio.h>
double ans=0;
int aans=0;
int main(){
    double m,n;
    scanf("%lf%lf",&m,&n);
    if(m<=3.0f)ans+=10.0;
    else if(m<=10.0f){
        ans+=10.0;
        ans+=(m-3)*2;
    }
    else{
        ans+=24.0;
        ans+=(m-10)*3;
    }
    if(n>5.0f){
        ans+=(int)((n-5)*0.4+0.5);
    }
    printf("%d",(int)(ans+0.5));
    return 0;
}
统计学生成绩
Description
输入一个正整数n,再输入n个学生的成绩,统计五分制成绩的成绩分布。百分制成绩到五分制成绩的转换规则:大于或等于90分为A,
小于90且大于或等于80分为B,小于80分且大于或等于70分为C,小于70分且大于或等于60为D,小于60分为E。试着编写相应程序。
Input
输入一个n 和n个学生的成绩,n为整数,学生成绩是double形式
Output
输出n个学生的五进制分数,中间用空格隔开。
Sample Input 1 
5
90 80 70 60 50
Sample Output 1
A B C D E
#include <stdio.h>
int a[666];
int main(){
    int n;
    scanf("%d",&n);
    float tmp;
    for(int i=1;i<=n;i++){
        scanf("%f",&tmp);
        if(tmp>=90.0f)a[i]=1;
        else if(tmp<90.0f&&tmp>=80.0f)a[i]=2;
        else if(tmp<80.0f&&tmp>=70.0f)a[i]=3;
        else if(tmp<70.0f&&tmp>=60.0f)a[i]=4;
        else a[i]=5;
    }
    for(int i=1;i<=n;i++){
        if(a[i]==1)printf("A");
        else if(a[i]==2)printf("B");
        else if(a[i]==3)printf("C");
        else if(a[i]==4)printf("D");
        else printf("E");
        printf(" ");
    }
    return 0;
}
三角形判断
Description
输入平面上任意三个点的坐标(x1,y1)、(x2,y2)、(x3,y3),检验它们能否构成三角形。如果这3个点能构成一个三角形。
如果这3个点能够构成一个三角形,输出周长和面积(2位小数);否则输出“Impossible”。试编写相应程序。
提示:在一个三角形中,任意两边之和大于第三边。三角形面积计算公式如下:
Area = sqrt(s(s-a)(s-b)(s-c)),其中s = (a+b+c)/2
Input
输入三个坐标值,按照顺序x1,y1,x2,y2,x3,y3。输入值为int类型。
Output
不能构成输出Impossible,否则输出周长和面积值(都保留两位小数,double类型)
Sample Input 1 
0 0 0 4 3 0
Sample Output 1
12.00 6.00
Sample Input 2 
1 2 4 5 7 8
Sample Output 2
Impossible
#include <stdio.h>
#include <math.h>
struct P{
    int x,y;
}p[4];
double ppow(double n){
    return n*n;
}
int main(){
    double a=0,b=0,c=0,s,tmp;
    for(int i=1;i<=3;i++)scanf("%d%d",&p[i].x,&p[i].y);
    a=sqrt(ppow((double) (p[1].x - p[2].x) )+ppow((double) (p[1].y - p[2].y)));
    b=sqrt(ppow((double) (p[2].x - p[3].x) )+ppow((double) (p[2].y - p[3].y)));
    c=sqrt(ppow((double) (p[1].x - p[3].x) )+ppow((double) (p[1].y - p[3].y)));
    s=(a+b+c)/2;
    tmp=s*(s-a)*(s-b)*(s-c);
    if(tmp>0){
        printf("%.2lf %.2lf",(double) (a+b+c),sqrt(tmp));
    }
    else printf("Impossible");

    return 0;
}