CodeVs天梯之Bronze
2017.12.18 By gwj1139177410
0x01整数处理
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int n; cin>>n;
int _max=-1, _min=0xfffffff;
for(int i = 1; i <= n; i++){
int x; cin>>x;
_max = max(_max, x);
_min = min(_min, x);
}
cout<<_min<<" "<<_max<<"\n";
return 0;
}
- 求和
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int n; cin>>n;
int sum = 0;
for(int i = 1; i <= n; i++){
int x; cin>>x;
sum += x;
}
cout<<sum<<"\n";
return 0;
}
0x02浮点数处理
#include<iostream>
using namespace std;
int main(){
float a, b; cin>>a>>b;
if(a == b)cout<<"yes\n";
else cout<<"no\n";
return 0;
}
- 保留两位小数
#include<cstdio>
int main(){
double x;
scanf("%lf", &x);
printf("%.2lf\n", x);
return 0;
}
- 机票打折
#include<iostream>
using namespace std;
int main(){
int n; float m;
cin>>n>>m;
int t = n*m/10;
if(t%10<=4)cout<<t-t%10<<"\n";
else cout<<t-t%10+10<<"\n";
return 0;
}
0x03字符串处理
- 寻找子串位置
#include<iostream>
#include<string>
using namespace std;
int main(){
string a, b;
cin>>a>>b;
cout<<a.find(b)+1<<"\n";
return 0;
}
- 单词翻转
#include<iostream>
#include<string>
using namespace std;
int main(){
string a[110];
int i = 1;
while(cin>>a[i])i++;
while(i--)cout<<a[i]<<" ";
return 0;
}