2020 The 11th Lanqiao Cup Competition Provincial Competition C/C++ Language University Group B Group F Question
Code:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,score; //n 学生人数,score得分
int nice=0,good=0;//good合格人数,nice优秀人数
float a=60,b=85;
scanf("%d",&n);
for (int i=0;i<n;i++){
scanf("%d",&score);
if (score >=60 ){
good +=1;
}
if( score >=85 && score <=100){
nice +=1;
}
}
float g1,g2;
g1 = good*100.0/n;
g2 = nice*100.0/n;
cout << setprecision(0)<<fixed<<g1<<"%\n"<<g2<<"%"<<endl ;
return 0;
}
important point:
1. Int/int finally gets the int type. If you want to finally get the float type, you might as well try int*1.0/int.
2. setprecision(0), controls the precision of the last output variable, fixed writes floating-point values in fixed-point representation. Use both together. Fixed-point representation:: The decimal point position of all data is fixed.
setprecision
Analysis of the results of Question F of Group A of C/C++ Language University in the 11th Lanqiao Cup Competition Provincial Competition in 2020
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int n;
scanf("%d",&n);
int max=0,min=100;
int score;
int sum;
float average;
for(int i=0;i<n;i++){
scanf("%d",&score);
if (score > max){
max = score;
}
else if(score <min){
min = score;
}
sum +=score;
}
average = sum*1.0/n;
cout << max << endl;
cout << min <<endl;
cout << setprecision(2) << fixed << average <<endl;
// 请在此输入您的代码
return 0;
}
// avg = round(average*100)/100;
2022c/c++ Language University Group B Question A
#include<bits/stdc++.h>
using namespace std;
int main()
{
// 请在此输入您的代码
string a = "2022";
int ans = 0;
for (int i=0;i<a.size();i++)
{
ans = ans * 9 + a[i] - '0';
}
cout << ans << endl;
return 0;
}
Leap year, ordinary year
#include <iostream>
using namespace std;
//每个月有多少天
int day[] = {
0,31,28,31,30,31,30,31,31,30,31,30,31
};
//判断是否为为闰年
int is_leap(int y){
return y%400==0 || y%4==0 && y%100!=0;
}
//计算该月有多少天
int dayOfMonth(int y,int m){
if (m==2)
return is_leap(y)+day[m];
return day[m];
}
int main()
{
int y = 2000,m=1,d=1,w=6;
int res= 0;//跑的公里数
while (y!=2020||m!=10||d!=2)
{
if(d==1||w==1)
res +=2;
else res ++;
d ++;
if(d>dayOfMonth(y,m))
d = 1,m ++;
if(m>12)
m=1,y++;
w++;
if(w==8)
w=1;
}
cout <<res <<endl;
return 0;
}
/*
8879
*/
&& has higher priority than ||.
#include <iostream>
using namespace std;
typedef long long LL;//long long:是64位的整型,取值范围为-2^63 ~ (2^63 - 1)。对应lld
int main()
{
LL a,b,n;
cin >>a >>b >>n;
LL d=0;
LL s = 5*a+2*b;
d += n/s*7;
n %=s;
for(int i=1;i<=7;i++){
if(n<=0) break;
else if(i<=5) n-=a;
else n-=b;
d++;
}
cout <<d <<endl;
return 0;
}
// #include<cstring>
// string b="123456789";
// b = b.substr(3,4);
// cout <<b <<endl; // 4567