打卡湘大OJ第1天

目录

1.谁拿了最多的奖学金

2.对齐输出

3.计算分数的浮点数值

4.甲流疫情死亡率

5.打印ASCII

6.大象喝水

7.一元二次方程

8.幂的后三位

9.求小数的某一位


1.谁拿了最多的奖学金

 

 

【C++】

#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int n;
    char cadre,west;
    int avr_grade,class_grade,paper;
    int prize=0,max=0,sum=0;
    string name,max_name=" ";
    int i;

    cin>>n;
    for(i=1;i<=n;i++)
    {
    	cin>>name>>avr_grade>>class_grade>>cadre>>west>>paper;//输入每个人的信息

        /*按要求进行奖学金汇总*/
        if( avr_grade>80 && paper>0)	prize+=8000;
        if( avr_grade>85 && class_grade>80)	prize+=4000;
    	if( avr_grade>90 )	prize+=2000;
    	if( avr_grade>85 && west=='Y')	prize+=1000;
    	if( class_grade>80 && cadre=='Y')	prize+=850;

        sum+=prize;//计算奖学金总和
        if( prize>max || (sum==0&&sum==max) )//记录最大奖学金
        {
           	max=prize;
        	max_name=name;
    	}
        prize=0;
    }

    /*数据输出*/
    cout<<max_name<<endl;
    cout<<max<<endl;
    cout<<sum<<endl;

    return 0;
}

2.对齐输出

【c】

#include <stdio.h>
#include <stdlib.h>
int main(){
   int a,b,c;
   scanf("%d%d%d",&a,&b,&c);
   printf("%8d%8d%8d",a,b,c);
   return 0;
}

3.计算分数的浮点数值

【C】

#include <stdio.h>
#include <stdlib.h>
int main(){
   int a,b;
   scanf("%d%d",&a,&b);
   double c=(double)a/b;
   printf("%.9f",c);
   return 0;
}

4.甲流疫情死亡率

【C】

#include <stdio.h>
#include <stdlib.h>
int main(){
   int a,b;
   scanf("%d%d",&a,&b);
   double c;
   c=(b*1.0/a)*100;
   printf("%.3lf%%\n",c);
   return 0;
}

5.打印ASCII

【C】

#include <stdio.h>
#include <stdlib.h>
int main(){
   char a;
   if(scanf("%c",&a)!=EOF){
    printf("%d\n",a);
   }
   return 0;
}

6.大象喝水

【C】

#include <stdio.h>
#include <stdlib.h>
int main(){
   int h,r,m;
   scanf("%d%d",&h,&r);
   double V=3.14159*h*r*r;
   double p=20000/V;
   m=(int)p;
   if(m==p){
    printf("%d",m);
   }else{
       printf("%d",m+1);
   }

   return 0;

}

7.一元二次方程

【C】

#include <stdio.h>
#include <stdlib.h>
#include<math.h>
int main(){
   double a,b,c;
   double m;
   double x1,x2;
   scanf("%lf%lf%lf",&a,&b,&c);
   if(b*b-4*a*c<0){
    printf("No answer!");
   }else if(b*b-4*a*c==0){
    m=(-b)/(2*a);
    printf("x1=x2=%.5lf\n",m);
   }else{
    x2=(-b-sqrt(b*b-4*a*c))/(2*a);
    x1=(-b+sqrt(b*b-4*a*c))/(2*a);
    if(x1<x2)
       printf("x1=%.5lf;x2=%.5lf\n",x1,x2);
    else
        printf("x1=%.5lf;x2=%.5lf\n",x2,x1);
   }
   return 0;

}

8.幂的后三位

【C++】

#include<bits/stdc++.h>  //万能头文件
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    int x=1;//保存a每次*b的末三位
    for(int i=1; i<=b; i++){
        x *=a;
        x = x%1000;
    }
    if(x<10)
        cout<<"00"<<x;
    else if(x<100)
        cout<<0<<x;
    else
        cout<<x;
    return 0;
}

9.求小数的某一位

【C++】

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int  a,b,c;
	int n;
	cin>>a>>b>>n;
	if(a>0&&a<100&&b>0&&b<100){
    for(;n<=10000&&n>=1;n--){
        c=a*10/b;
		a=(10*a)%b;
    }
	}
    cout<<c;
	return 0;
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值