信息学奥赛一点通C++第一章答案
1000
#include <bits/stdc++.h>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
cout<<(a+b);
return 0;
}
2060
#include <bits/stdc++.h>
using namespace std;
int main(){
cout<<"Hello World!";
return 0;
}
2061
#include <bits/stdc++.h>
using namespace std;
int main(){
printf("%0.2f\n",(15.0+25.0)*(150.0/15.0*2.0)/2.0);
return 0;
}
2062
#include <bits/stdc++.h>
using namespace std;
int main(){
int x;
cin>>x;
cout<<x<<' '<<(x*10);
return 0;
}
2063
#include <bits/stdc++.h>
using namespace std;
int main(){
int s;
s=(15*20-20*10)/10;
cout<<s;
return 0;
}
1001
#include <bits/stdc++.h>
using namespace std;
int main(){
cout<<"Hello,World!";
return 0;
}
1002
#include <bits/stdc++.h>
using namespace std;
int main(){
int a,b,c;
cin>>a>>b>>c;
cout<<b;
return 0;
}
1003
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;
cout<<setw(8)<<a<<' '<<setw(8)<<b<<' '<<setw(8)<<c;
return 0;
}
注:使用setw()函数需要设置头文件为#include ,iomanip的作用是对输入输出做一些操作。需要注意的是 setw(n)设置宽度,若是实际宽度大于被设置的,则setw函数此时失效。
1004
#include<bits/stdc++.h>
using namespace std;
int main(){
char a;
cin>>a;
cout<<" "<<" "<<a<<endl;
cout<<" "<<a<<a<<a<<endl;
cout<<a<<a<<a<<a<<a<<endl;
return 0;
}
1005
#include <bits/stdc++.h>
using namespace std;
int main(){
int x,a,y,b;
double z;
cin>>x>>a>>y>>b;
z=(b*y-a*x)/(b-a);
cout<<fixed<<setprecision(2)<<z;
return 0;
}
注:setprecision()这个函数要调用头文件iomanip,有fixed在前面函数参数就是指小数点后有几位数。如果没有fixed在前则函数参数表示输出结果总共有几位数,其余的舍弃;但若参数<整数位数,结果则为指数形式输出。