所有题答案

成绩等级
cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
int a;
cin>>a;
if(a>=90) cout<<'A';
else if(a>=80) cout<<'B';
else if(a>=70) cout<<'C';
else if(a>=60) cout<<'D';
else cout<<'E';
return 0;
}

逆序输出各位数字
cpp
#include<bits/stdc++.h>
using namespace std;
string s;
signed main(){
cin>>s;
cout<<s.size()<<"\n";
for(int i=0;i<s.size();i++) cout<<s[i]<<' ';
cout<<"\n";
for(int i=s.size()-1;i>=0;i--) cout<<s[i];
return 0;
}

时间计数
cpp
#include<bits/stdc++.h>
using namespace std;
#define int long long
int a,b,c;
char d;
signed main(){
cin>>a>>b>>c>>d;
if(d=='P') a+=12;
cout<<a*3600+b*60+c;
return 0;
}

闰年的次数
cpp
#include<bits/stdc++.h>
using namespace std;
bool run(int a){
if((a%4==0&&a%100!=0)||(a%400==0)) return true;
return false;
}
int t,l,r;
signed main(){
cin>>l>>r;
for(int i=l;i<=r;i++){
if(run(i)) t++;
}
cout<<t;
return 0;
}

每月天数
cpp
#include<bits/stdc++.h>
using namespace std;
int m[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int main(){
int a,b;
cin>>a>>b;
if((a%4==0&&a%100!=0)||(a%400==0)) m[2]++;
cout<<m[b];
return 0;
}

长方形面积
cpp
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,t;
signed main(){
cin>>n;
for(int i=1;i*i<=n;i++) if(n%i==0) t++;
cout<<t;
return 0;
}

5 条评论

  • 1