码蹄集新手村100题答案
Posted zstar-_
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了码蹄集新手村100题答案相关的知识,希望对你有一定的参考价值。
码蹄集是今年新上线的一个OJ平台,内含了100道基础题和一些百度之星的题目。由于很多题目有原创性,搜不到相关解答,因此我花了两天特将100道题目刷了一遍,目前位居榜二。
码蹄集传送门:https://www.matiji.net/exam/ojquestionlist
前言
所有题目均能AC,不一定是最佳方法,如有其它方法,可在评论区留言讨论。
1、程序设计入门
#include <iostream>
using namespace std;
int main( )
cout << "This is my first program!" << endl;
cout << "Coding is fun!" << endl;
return 0;
2、输入和输出整型数据
#include <iostream>
using namespace std;
int main( )
int a;
cin >> a;
cout << "You entered:"<< a;
return 0;
3、输入和输出实型数据
#include <iostream>
#include <iomanip>
using namespace std;
int main()
float a;
double b;
cin >> a;
cin >> b;
cout << "You entered:" << setiosflags(ios::fixed) << setprecision(2) << a << " and " << setiosflags(ios::fixed) << setprecision(3) << b;
return 0;
4、输入和输出字符型数据
#include <iostream>
using namespace std;
int main()
int a, b;
scanf_s("%d,%d", &a,&b);
cout << a << "+" << b << "=" << a+b << endl;
cout << a << "-" << b << "=" << a-b;
return 0;
5、整数运算
#include <iostream>
using namespace std;
int main()
int a, b;
scanf("%d,%d", &a,&b);
cout << a << "+" << b << "=" << a+b << endl;
cout << a << "-" << b << "=" << a-b;
return 0;
6、实型数运算
#include <iostream>
#include <iomanip>
using namespace std;
int main()
double a, b;
cin >> a >> b;
cout << setiosflags(ios::fixed) << setprecision(6) << a << "*" << setiosflags(ios::fixed) << setprecision(6) << b << "=" << setiosflags(ios::fixed) << setprecision(6) << a * b << endl;
cout << setiosflags(ios::fixed) << setprecision(6) << a << "/" << setiosflags(ios::fixed) << setprecision(6) << b << "=" << setiosflags(ios::fixed) << setprecision(6) << a / b;
return 0;
7、求余
#include <iostream>
using namespace std;
int main( )
int a,b,c,d;
cin >> a >> b >> c >> d;
cout << a << "%" << b << "=" << a%b << endl;
cout << c << "%" << d << "=" << c%d;
return 0;
8、各种类型长
#include <iostream>
using namespace std;
int main()
cout << "Size of int: " << sizeof(int) << " bytes" << endl;
cout << "Size of float: " << sizeof(float) << " bytes" << endl;
cout << "Size of double: " << sizeof(double) << " bytes" << endl;
cout << "Size of char: " << sizeof(char) << " byte";
return 0;
9 、关键字long
#include <iostream>
using namespace std;
int main()
cout << "Size of int = " << sizeof(int) << " bytes" << endl;
cout << "Size of long int = " << sizeof(long int) << " bytes" << endl;
cout << "Size of long long int = " << sizeof(long long int) << " bytes" << endl;
cout << "Size of double = " << sizeof(double) << " bytes" << endl;
cout << "Size of long double = " << sizeof(long double) << " bytes" ;
return 0;
10、交换
#include <iostream>
using namespace std;
int main( )
int a,b;
cin >> a >> b;
cout << b << " " << a;
return 0;
11、求圆面积和周长
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
#define pi 3.1415926
int main()
double r;
cin >> r;
cout << "Area=" << setiosflags(ios::fixed) << setprecision(6) << pi * r * r << endl;
cout << "Circumference=" << setiosflags(ios::fixed) << setprecision(6) << 2 * pi * r;
return 0;
12、求矩形面积和周长
#include <iostream>
using namespace std;
int main()
double a, b;
cin >> a >> b;
printf("Area=%.6f\\n", a * b);
printf("Perimeter=%.6f", a * 2 + b * 2);
return 0;
13、椭圆计算
#include <iostream>
#include <iomanip>
using namespace std;
# define pi 3.1415926
int main( )
double a,b;
cin >> a >> b;
cout << "Area = " << setiosflags(ios::fixed) << setprecision(6) << pi * a * b;
return 0;
14、圆锥的表面积
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
# define pi 3.1415926
int main()
double r, h, area;
cin >> r >> h;
area = pi * r * (r + sqrt(pow(r, 2) + pow(h, 2)));
cout << "Surface area=" << setiosflags(ios::fixed) << setprecision(2) << area;
return 0;
15、三角形面积
#include <iostream>
#include<iomanip>
using namespace std;
int main( )
float a,b;
cin >> a >> b;
cout << "Area=" << setiosflags(ios::fixed) << setprecision(2) << 0.5 * a * b;
return 0;
16、平方根和对数值
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
double a;
cin >> a;
cout << setiosflags(ios::fixed) << setprecision(2) << sqrt(a) << " " << setiosflags(ios::fixed) << setprecision(2) << log(a) << " " << setiosflags(ios::fixed) << setprecision(2) << log10(a);
return 0;
17、坐标的转换
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
#define pi 3.1415926
int main()
float x, y;
cin >> x >> y;
cout << setiosflags(ios::fixed) << setprecision(1) << sqrt(pow(x, 2) + pow(y, 2)) << " " << setiosflags(ios::fixed) << setprecision(1) << atan(y/x)*180/pi;
return 0;
18、分期付款
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main( )
double p ,r , n;
cin >> p >> r >> n;
r = r/(12*100);
double rate = p * r * pow(1+r,n)/(pow(1+r,n)-1);
cout << setiosflags(ios::fixed) << setprecision(1) << rate;
return 0;
19、极坐标到笛卡尔坐标的转换
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
#define pi 3.1415926
int main()
double r, theta;
cin >> r >> theta;
double x = r * cos(theta * pi / 180);
double y = r * sin(theta * pi / 180);
cout << setiosflags(ios::fixed) << setprecision(2) << x << "," << setiosflags(ios::fixed) << setprecision(2) << y;
return 0;
20、公里转换成米
#include <iostream>
#include <iomanip>
using namespace std;
int main( )
double a;
cin >> a;
cout << setiosflags(ios::fixed) << setprecision(2) << a << "公里="<< setiosflags(ios::fixed) << setprecision(2) << a*1000 << "米";
return 0;
21、和10相比
#include <iostream>
using namespace std;
int main( )
int a;
cin >> a;
if (a<10)
cout << a << "小于10";
else if (a == 10)
cout << a << "等于10";
else
cout << a << "大于10";
return 0;
22、成绩评语
#include <iostream>
using namespace std;
int main()
char a;
cin >> a;
if (a == 'A')
cout << "Excellent";
else if (a == 'B')
cout << "Well done";
else if (a == 'C')
cout << "You passed";
else if (a == 'D')
cout << "Better luck next time";
else
cout << "Invalid grade";
return 0;
23、元音
#include <iostream>
using namespace std;
int main( )
char a;
cin >> a;
if (a == 'A' or a == 'E' or a =='I' or a == 'O' or a == 'U') cout << "Y";
else cout << "N";
return 0;
24、大小写的转换
#include <iostream>
using namespace std;
int main()
char a;
cin >> a;
if (a >= 'a' & a <= 'z')
cout << char(a - 32);
else if (a >= 'A' & a <= 'Z')
cout << char(a + 32);
else
cout << a;
return 0;
25、最小值
#include <iostream>
using namespace std;
int main( )
int a,b;
cin >> a >> b;
if (a > b) cout << b;
else cout << a;
return 0;
26、最大值
#include <iostream>
using namespace std;
int main( )
int a,b;
cin >> a >> b;
if (a > b) cout << a;
else cout << b;
return 0;
27、中庸之道
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
int a, b, c;
cin >> a >> b >> c;
vector<int> v;
v.push_back(a);
v.push_back(b);
v.push_back(c);
sort(v.begin(), v.end());
cout << v[1算法竞赛入门码蹄集新手村600题(MT1351-1400)