因为本人能力不足(还是初学者)所以只挑了简单的做了一下
宝子们轻喷(有意见提意见,别骂我*-*)
#1. A + B Problem
输入 a和b,输出a+b的结果。
参考程序
#include <iostream>
using namespace std;
int main() {
int a, b;
while (cin >> a >> b) cout << a + b << endl;
return 0;
}
#2. Hello, World!
输出 Hello, World!
参考程序
#include <iostream>
using namespace std;
int main() {
cout << "Hello, World!";
return 0;
}
#3. Copycat
这道题用于测试文件输入输出,请注意使用文件输入输出,而非标准输入输出。
输入一个正整数a,输出这个数a。
参考程序
#include <bits/stdc++.h>
using namespace std;
int main() {
freopen("copycat.in", "r", stdin);
freopen("copycat.out", "w", stdout);
int quantity;
cin >> quantity;
string a;
for (int i = 1; i <= quantity; i++) {
cin >> a;
cout << a << endl;
}
return 0;
}
#5. 芯片测试
有n(2≤n≤20)块芯片,有好有坏,已知好芯片比坏芯片多。
每个芯片都能用来测试其他芯片。用好芯片测试其他芯片时,能正确给出被测试芯片是好还是坏。而用坏芯片测试其他芯片时,会随机给出好或是坏的测试结果(即此结果与被测试芯片实际的好坏无关)。
参考程序
#include <iostream>
using namespace std;
int main() {
int arr[25][25] = { 0 };
int n;
cin >> n;
int brr[n] = { 0 };
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> arr[i][j];
if (arr[i][j] == 1) {
brr[j]++;
}
}
}
int goal = n / 2;
for (int i = 0; i < n; i++) {
if (brr[i] > goal)
cout << i + 1 << ' ';
}
return 0;
}
#7. 字符正方形
参考答案
#include <bits/stdc++.h>
using namespace std;
int main() {
char x;
cin >> x;
cout << x << x << x << endl;
cout << x << x << x << endl;
cout << x << x << x;
return 0;
}
#8. 长方形面积
从键盘上输入一个字符,用它构造一个边长是3个字符的正方形。
参考程序
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << a * b;
return 0;
}
#9. 圆面积
从键盘上输入圆的半径,计算面积并输出(保留2位小数)。
参考程序
#include <bits/stdc++.h>
using namespace std;
int main() {
double r;
cin >> r;
printf("%.2f", r * r * 3.14);
return 0;
}
#10. 整数求和
从键盘输入2个整数,输出它们的和。
参考答案
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << a + b << endl;
return 0;
}
#11. 长方形面积、周长
输入长方形的长和宽,输出长方形的面积与周长。
参考答案
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << a * b << endl;
cout << (a + b) * 2;
return 0;
}
#65. 到底多少秒?
1年365天,1天24小时,1小时60分,1分钟60秒,请问 N 年合计多少秒钟?
参考程序
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
long long x;
cin >> n >> x;
x = 365 * 24 * 60 * 60;
cout << n * x << endl;
return 0;
}
#66. 输出余数
输入一个五位数a,求a除以10,100,1000的余数,并输出。
参考程序
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a;
cin >> a;
cout << a % 10 << endl;
cout << a % 100 << endl;
cout << a % 1000;
return 0;
}
#71. 鸡兔同笼
鸡和兔关在一个笼子里,鸡有2只脚,兔有4只脚,没有例外。
已知现在可以看到笼子里面有m个头和n只脚,求鸡兔各有多少只?
参考程序
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, n;
cin >> m >> n;
for (int i = 1; i < m; i++) {
for (int j = 1; j < m; j++)
if ((i + j == m) && (i * 2 + j * 4 == n))
cout << i << " " << j << endl;
}
}
#76. 小数的指定位等于多少?
分数a/b化为小数后,小数点后第n位的数字是多少?
参考程序
#include <stdio.h>
int main() {
int a, b, n, c;
scanf("%d %d %d", &a, &b, &n);
if (a > b)
a = a % b;
for (int i = 1; i <= n; i++) {
c = 10 * a / b;
a = 10 * a - b * c;
}
printf("%d\n", c);
return 0;
}
#94. 计算三角形面积
输入底和高,输出三角形面积(保留1位小数)
参考程序
#include <bits/stdc++.h>
using namespace std;
int main() {
float x, y;
cin >> x >> y;
printf("%.1f", x * y / 2);
return 0;
}
#267. 竖式计算
数学老师请你帮忙,在屏幕上输出两个数的竖式加法计算。
例如:
18 //列宽为10
+ 870 //列宽为4 和 6
----------- //11个减号
888 //列宽为10
参考程序
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << " " << a << endl;
cout << " + " << b << endl;
cout << "-----------" << endl;
cout << " " << a + b << endl;
return 0;
}
#10007. 输出第二个整数
输入三个整数,把第二个输入的整数输出。
参考程序
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y, z;
cin >> x >> y >> z;
cout << y << endl;
return 0;
}
#10008. 浮点数向零舍入
输入一个单精度浮点数,将其向零舍入到整数。说明: 向零舍入的含义是,正数向下舍入,负数向上舍入。提示: 可以使用强制类型转换来实现。
参考程序
#include <cstdio>
using namespace std;
int main() {
float a;
int b;
scanf("%f", &a);
b = int(a);
printf("%d", b);
return 0;
}