ac代码,100%放心
第一节 运算符和表达式
1006代码
#include <iostream>
using namespace std;
int a, b;
int main ( )
{
cin>> a>> b;
cout<< a+ b<< endl;
return 0 ;
}
1007代码
#include <iostream>
using namespace std;
int a, b, c;
int main ( )
{
cin>> a>> b>> c;
cout<< ( a+ b) * c<< endl;
return 0 ;
}
1008代码
#include <iostream>
using namespace std;
int a, b, c;
int main ( )
{
cin>> a>> b>> c;
cout<< ( a+ b) / c<< endl;
return 0 ;
}
1009代码
#include <iostream>
using namespace std;
int a, b, c;
int main ( )
{
cin>> a>> b;
cout<< a/ b<< " " << a% b<< endl;
return 0 ;
}
1010代码
#include <bits/stdc++.h>
using namespace std;
int main ( ) {
int a, b;
cin>> a>> b;
cout<< fixed<< setprecision ( 9 ) << ( 1.0 * a / b) / 10 * 10 ;
return 0 ;
}
第二节 常量和变量
1011代码
#include <bits/stdc++.h>
using namespace std;
int main ( ) {
int a, b;
cin>> a>> b;
cout<< fixed<< setprecision ( 3 ) << 100.0 * b / a<< "%" ;
return 0 ;
}
1012代码
#include <bits/stdc++.h>
using namespace std;
int main ( ) {
double x, a, b, c, d;
cin>> x>> a>> b>> c>> d;
cout<< fixed<< setprecision ( 7 ) << a* x* x* x + b* x* x + c* x + d;
return 0 ;
}
1013代码
#include <bits/stdc++.h>
using namespace std;
int main ( ) {
double F, C;
cin>> F;
C = 5 * ( F - 32 ) / 9 ;
cout<< fixed<< setprecision ( 5 ) << C;
return 0 ;
}
1014代码
#include <bits/stdc++.h>
using namespace std;
int main ( ) {
double r, d, l , s;
double pi = 3.14159 ;
cin>> r;
d = 2 * r;
l = 2 * pi * r;
s = pi * r * r;
cout<< fixed<< setprecision ( 4 ) << d<< " " << l<< " " << s;
return 0 ;
}
1015代码
#include <bits/stdc++.h>
using namespace std;
int main ( ) {
double r1, r2, R;
cin>> r1>> r2;
R = 1.0 / ( 1.0 / r1 + 1.0 / r2) ;
cout<< fixed<< setprecision ( 2 ) << R;
return 0 ;
}
第三节 标准数据类型
1016代码
#include <bits/stdc++.h>
using namespace std;
int main ( ) {
int a;
short b;
cout << sizeof ( a) << ' ' << sizeof ( b) << endl;
return 0 ;
}
1017代码
#include <bits/stdc++.h>
using namespace std;
int main ( ) {
float a;
double b;
cout << sizeof ( a) << ' ' << sizeof ( b) << endl;
return 0 ;
}
1018代码
#include <bits/stdc++.h>
using namespace std;
int main ( ) {
bool a;
char b;
cout << sizeof ( a) << ' ' << sizeof ( b) << endl;
return 0 ;
}
1019代码
#include <bits/stdc++.h>
using namespace std;
int main ( ) {
float a;
cin >> a;
cout << ( int ) a << endl;
return 0 ;
}
1020代码
#include <bits/stdc++.h>
using namespace std;
int main ( ) {
char ch;
cin>> ch;
cout<< ( int ) ch;
return 0 ;
}
1021代码
#include <bits/stdc++.h>
using namespace std;
int main ( ) {
int a;
cin>> a;
cout<< ( char ) a;
return 0 ;
}
1022代码
#include <bits/stdc++.h>
using namespace std;
int main ( ) {
int a;
bool b;
int c;
cin>> a;
b = a;
c = b;
cout<< c;
return 0 ;
}
1023代码
#include <bits/stdc++.h>
using namespace std;
int main ( ) {
cout << sizeof ( "Hello, World!" ) << endl;
return 0 ;
}
第四节 数据输入输出
1024代码
#include <bits/stdc++.h>
using namespace std;
int main ( ) {
float a;
cin>> a;
cout<< fixed<< setprecision ( 3 ) << a;
return 0 ;
}
1025代码
#include <bits/stdc++.h>
using namespace std;
int main ( ) {
float a;
cin>> a;
cout<< fixed<< setprecision ( 12 ) << a;
return 0 ;
}
1026代码
#include <bits/stdc++.h>
using namespace std;
int main ( ) {
char a;
int b;
float c;
double d;
cin>> a>> b>> c>> d;
cout<< a<< " " << b<< " " << fixed<< setprecision ( 6 ) << c<< " " << d;
return 0 ;
}
1027代码
#include <iostream>
#include <cstdio>
using namespace std;
int main ( )
{
double n;
cin>> n;
printf ( "%f\n" , n) ;
printf ( "%.5f\n" , n) ;
printf ( "%e\n" , n) ;
printf ( "%g\n" , n) ;
return 0 ;
}
1028代码
#include <iostream>
using namespace std;
int main ( )
{
char ch;
cin>> ch;
cout<< " " << ch<< endl;
cout<< " " << ch<< ch<< ch<< endl;
cout<< ch<< ch<< ch<< ch<< ch<< endl;
cout<< " " << ch<< ch<< ch<< endl;
cout<< " " << ch<< endl;
return 0 ;
}
第五节 顺序结构实例
1029代码
#include <iostream>
using namespace std;
int main ( ) {
double a, b, r;
cin >> a >> b;
r = a - int ( a / b) * b;
cout << r << endl;
return 0 ;
}