网站整体设计流程,会计网站建设,短域名转换,网站安全建设架构目录
1. Hello World!
2. 据说一个人的标准体重应该是其身高#xff08;单位#xff1a;厘米#xff09;减去100、再乘以0.9所得到的公斤数。已知市斤的数值是公斤数值的两倍。现给定某人身高#xff0c;请你计算其标准体重应该是多少#xff1f;
3. 给定一个华氏温度F…目录
1. Hello World!
2. 据说一个人的标准体重应该是其身高单位厘米减去100、再乘以0.9所得到的公斤数。已知市斤的数值是公斤数值的两倍。现给定某人身高请你计算其标准体重应该是多少
3. 给定一个华氏温度F计算对应的摄氏温度C。计算公式C5×(F−32)/9。题目保证输入与输出均在整型范围内。
4. 计算4个整数的和与平均值。题目保证输入与输出均在整型范围内。
5. 程序每次读入一个正3位数然后输出按位逆序的数字。注意当输入的数字含有结尾的0时输出不应带有前导的0。比如输入700输出应该是7。 6. 输出21世纪中截止某个年份以来的所有闰年年份。注意闰年的判别条件是该年年份能被4整除但不能被100整除、或者能被400整除。
7. 将输入的任意3个整数从小到大输出。
8. 对于给定的正整数N求它的位数及其各位数字之和。
9. 给定N个正整数请统计奇数和偶数各有多少个
10. 将输入的一系列整数中的最小值与第一个数交换然后将最大值与最后一个数交换最后输出交换后的序列。注意题目保证最大和最小值都是唯一的。
11. 从输入的N个整数中查找给定的X。如果找到输出X的位置从0开始数如果没有找到输出“Not Found”。
12. 对于给定的正整数N需要你计算 S1!2!3!...N!。
13. 对任意给定的一位正整数N输出从1*1到N*N的部分口诀表。下面是一个完整的下三角九九口诀表
14. 求一个给定的m×n矩阵各行元素之和。
15. 求两个给定正整数的最大公约数和最小公倍数。 1. Hello World!
本题要求编写程序输出一个短句“Hello World!”。输入格式:
本题目没有输入。输出格式:
在一行中输出短句“Hello World!”。
答案
#includeiostream
using namespace std;int main(){coutHello World!;
} 2. 据说一个人的标准体重应该是其身高单位厘米减去100、再乘以0.9所得到的公斤数。已知市斤的数值是公斤数值的两倍。现给定某人身高请你计算其标准体重应该是多少
输入格式
输入第一行给出一个正整数H100 H ≤ 300为某人身高。输出格式
在一行中输出对应的标准体重单位为市斤保留小数点后1位。输入样例
169输出样例
124.2
答案
#include iostream
#include cstdio
using namespace std;
int main() {double n;scanf(%lf, n);printf(%.1lf, (n - 100) * 1.8);return 0;
} 3. 给定一个华氏温度F计算对应的摄氏温度C。计算公式C5×(F−32)/9。题目保证输入与输出均在整型范围内。
输入格式:
输入在一行中给出一个华氏温度。输出格式:
在一行中按照格式“Celsius C”输出对应的摄氏温度C的整数值。输入样例:
150输出样例:
Celsius 65
答案
#includeiostream
using namespace std;int main(){int f; cinf;int c 5*(f-32)/9;coutCelsius c;return 0;
} 4. 计算4个整数的和与平均值。题目保证输入与输出均在整型范围内。
输入格式:
输入在一行中给出4个整数其间以空格分隔。输出格式:
在一行中按照格式“Sum 和; Average 平均值”顺序输出和与平均值其中平均值精确到小数点后一位。输入样例:
1 2 3 4
输出样例:
Sum 10; Average 2.5
答案
#include cstdio
#include iostream
using namespace std;int main() {int a, b, c, d;scanf(%d%d%d%d, a, b, c, d);int sum a b c d;printf(Sum %d; Average %.1lf, sum, sum / 4.0);return 0;
} 5. 程序每次读入一个正3位数然后输出按位逆序的数字。注意当输入的数字含有结尾的0时输出不应带有前导的0。比如输入700输出应该是7。
输入格式
每个测试是一个3位的正整数。输出格式
输出按位逆序的数。输入样例
123
输出样例
321
答案
#include cstdio
#include iostream
using namespace std;int main() {int t, a 0;cin t;while (t) {a a * 10 t % 10;t / 10;}cout a;return 0;
} 6. 输出21世纪中截止某个年份以来的所有闰年年份。注意闰年的判别条件是该年年份能被4整除但不能被100整除、或者能被400整除。
输入格式:
输入在一行中给出21世纪的某个截止年份。输出格式:
逐行输出满足条件的所有闰年年份即每个年份占一行。
输入若非21世纪的年份则输出Invalid year!。若不存在任何闰年则输出“None”。输入样例1:
2048
输出样例1:
2004
2008
2012
2016
2020
2024
2028
2032
2036
2040
2044
2048输入样例2:
2000
输出样例2:
Invalid year!
答案
#include algorithm
#include cstdio
#include iostream
using namespace std;int main() {int n, cnt 0;cin n;if (n 2000 || n 2100) {cout Invalid year!;return 0;}for (int i 2001; i n; i) {if (i % 4 0 i % 100 ! 0 || i % 400 0) {cout i endl;cnt;}}if (cnt 0)cout None;return 0;
} 7. 将输入的任意3个整数从小到大输出。
输入格式:
输入在一行中给出3个整数其间以空格分隔。输出格式:
在一行中将3个整数从小到大输出其间以“-”相连。输入样例:
4 2 8
输出样例:
2-4-8
答案
#include algorithm
#include cstdio
#include iostream
using namespace std;int main() {int a, b, c;cin a b c;if (a b) {int t a;a b;b t;}if (a c) {int t a;a c;c t;}if (b c) {int t b;b c;c t;}cout a - b - c;return 0;
} 8. 对于给定的正整数N求它的位数及其各位数字之和。
输入格式
输入在一行中给出一个不超过109的正整数N。输出格式
在一行中输出N的位数及其各位数字之和中间用一个空格隔开。输入样例
321
输出样例
3 6
答案
#include algorithm
#include cstdio
#include iostream
using namespace std;int main() {int n; cin n;int a 0, b 0;while (n) {a;b n % 10;n / 10;}cout a b;return 0;
} 9. 给定N个正整数请统计奇数和偶数各有多少个
输入格式
输入第一行给出一个正整N≤1000第2行给出N个非负整数以空格分隔。输出格式
在一行中先后输出奇数的个数、偶数的个数。中间以1个空格分隔。输入样例
9
88 74 101 26 15 0 34 22 77
输出样例
3 6
答案
#include algorithm
#include cstdio
#include iostream
using namespace std;int main() {int n, a 0, x;cin n;for (int i 1; i n; i) {cin x;if (x % 2 0){a;}}cout n - a a;return 0;
} 10. 将输入的一系列整数中的最小值与第一个数交换然后将最大值与最后一个数交换最后输出交换后的序列。注意题目保证最大和最小值都是唯一的。
输入格式
输入在第一行中给出一个正整数N≤10第二行给出N个整数数字间以空格分隔。输出格式
在一行中顺序输出交换后的序列每个整数后跟一个空格。输入样例
5
8 2 5 1 4
输出样例
1 2 5 4 8
答案
#include algorithm
#include cstdio
#include iostream
using namespace std;int main() {int a[11], n;cin n;for (int i 1; i n; i)cin a[i];int id 1;for (int i 1; i n; i) {if (a[id] a[i])id i;}swap(a[id], a[1]);for (int i 1; i n; i) {if (a[id] a[i])id i;}swap(a[id], a[n]);for (int i 1; i n; i)cout a[i] ;//每个整数后跟一个空格return 0;
} 11. 从输入的N个整数中查找给定的X。如果找到输出X的位置从0开始数如果没有找到输出“Not Found”。
输入格式
输入在第一行中给出两个正整数N≤20和X第二行给出N个整数。数字均不超过长整型其间以空格分隔。输出格式
在一行中输出X的位置或者“Not Found”。输入样例1
5 7
3 5 7 1 9
输出样例1
2输入样例2
5 7
3 5 8 1 9
输出样例2
Not Found
答案
#include algorithm
#include cstdio
#include iostream
using namespace std;int main() {int a[21], n, x, id 0;cin n x;for (int i 0; i n; i)cin a[i];for (int i 0; i n; i) {if (a[i] x) {id i;}}if (a[id] ! x)cout Not Found;elsecout id;return 0;
} 12. 对于给定的正整数N需要你计算 S1!2!3!...N!。
输入格式
输入在一行中给出一个不超过10的正整数N。输出格式
在一行中输出S的值。输入样例
3
输出样例
9
答案
#include algorithm
#include cstdio
#include iostream
using namespace std;int main() {int n, s 0, t 1;cin n;for (int i 1; i n; i) {t t * i; // t i!s t;}cout s;return 0;
} 13. 对任意给定的一位正整数N输出从1*1到N*N的部分口诀表。下面是一个完整的下三角九九口诀表
1*11
1*22 2*24
1*33 2*36 3*39
1*44 2*48 3*412 4*416
1*55 2*510 3*515 4*520 5*525
1*66 2*612 3*618 4*624 5*630 6*636
1*77 2*714 3*721 4*728 5*735 6*742 7*749
1*88 2*816 3*824 4*832 5*840 6*848 7*856 8*864
1*99 2*918 3*927 4*936 5*945 6*954 7*963 8*972 9*981 输入格式
输入在一行中给出一个正整数N1≤N≤9。输出格式
输出下三角N*N部分口诀表其中等号右边数字占4位、左对齐。输入样例
4
输出样例
1*11
1*22 2*24
1*33 2*36 3*39
1*44 2*48 3*412 4*416
答案
#include cstdio
#include iostream
using namespace std;int main() {int n;scanf(%d, n);for (int i 1; i n; i) {for (int j 1; j i; j) {printf(%d*%d%-4d, j, i, i * j);}puts();}return 0;
} 14. 求一个给定的m×n矩阵各行元素之和。
输入格式
输入第一行给出两个正整数m和n1≤m,n≤6。随后m行每行给出n个整数其间以空格分隔。输出格式
每行输出对应矩阵行元素之和。输入样例
3 2
6 3
1 -8
3 12
输出样例
9
-7
15
答案
#include iostream
using namespace std;int main() {int m, n;cin m n;for (int i 0; i m; i) {int sum 0, a;for (int j 0; j n; j) {cin a;sum a;}cout sum endl;}return 0;
} 15. 求两个给定正整数的最大公约数和最小公倍数。
输入格式:
输入在一行中给出两个正整数M和N≤1000。输出格式:
在一行中顺序输出M和N的最大公约数和最小公倍数两数字间以1空格分隔。输入样例:
511 292
输出样例:
73 2044
答案
#include iostream
using namespace std;int main() {int a, b;cin a b;int x a, y b, tmp 0;while (y ! 0) {tmp x % y;x y;y tmp;}cout x a * b / x;return 0;
}