2022/3/30
离比赛还有25天
练习L1-031到L1-035
L1-031 到底是不是太胖了 (10 分)
代码:
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
double h,w;
cin>>h>>w;
double weight=abs(h-100)*0.9*2;//标准体重;
if(abs(w-weight)<(weight)*0.1){
cout<<"You are wan mei!"<<"\n";
}else if(w<weight){
cout<<"You are tai shou le!"<<"\n";
}else {
cout<<"You are tai pang le!"<<"\n" ;
}
}
return 0;
}
L1-032 Left-pad (20 分)
代码: ?
#include<iostream>
using namespace std;
int main(){
int n;
char c;
cin>>n>>c;
getchar();//用了cin会在缓冲区留下一个回车,要用getchar吸收掉,不然会影响到下面getline的读入;
string s;
getline(cin,s);
int len=s.length();
if(len>n){
string s1=s.substr(len-n,n);
cout<<s1<<"\n";
}else {
for(int i=0;i<n-len;i++){
cout<<c;
}
cout<<s;
}
return 0;
}
L1-033 出生年 (15 分)
代码:
#include<iostream>
#include<set>
using namespace std;
int main(){
int year,n;
cin>>year>>n;
const int maxn=10010;
for(int i=year;i<maxn;i++){
int cnt=0;
set<int> m;
int num=i;
for(int j=0;j<4;j++){
int y=num%10;
num/=10;
m.insert(y);
}
if(m.size()==n){
printf("%d %04d",i-year,i);
break;
}
}
return 0;
}
L1-034 点赞 (20 分)
代码:
#include<iostream>
using namespace std;
int main(){
const int maxn=10010;
int a[maxn]={0};
int n;
cin>>n;
for(int i=0;i<n;i++){
int m;
cin>>m;
for(int j=0;j<m;j++){
int temp;
cin>>temp;
a[temp]++;
}
}
int maxnum=0,maxcnt=0;
for(int i=0;i<maxn;i++){
if(a[i]>=maxcnt){
maxnum=i;
maxcnt=a[i];
}
}
cout<<maxnum<<" "<<maxcnt;
return 0;
}
L1-035 情人节 (15 分)
代码:
#include<iostream>
#include<vector>
using namespace std;
int main(){
int cnt=0;
string str[10010];
while(1){
string s;
cin>>s;
if(s==".")break;
str[cnt++]=s;
}
if(cnt>=14){
printf("%s and %s are inviting you to dinner...",str[1].c_str(),str[13].c_str());//printf是c的产物string是c++的产物,要想printf输出string类型就要用函数.c_str()将string对象转换为c中字符串的样式
}else if(cnt<14&&cnt>=2){
printf("%s is the only one for you...",str[1].c_str());
}else if(cnt<2){
printf("Momo... No one is for you ...");
}
return 0;
}
|