
c++
Harore
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
斐波那契数列
Problem Description 编写计算斐波那契(Fibonacci)数列的第n项函数fib(n)(n<40)。 数列: f1=f2==1; fn=fn-1+fn-2(n>=3)。 Input 输入整数n的值。 Output 输出fib(n)的值。 Sample Input 7 Sample Output 13 Hint Source #include using namesp...原创 2019-02-14 22:12:49 · 265 阅读 · 0 评论 -
c++中如何保留小数点后位数
#include #include using namespace std; int main(){ float a; while(cin>>a){ if(a>0) cout<<setiosflags(ios::fixed)<<setprecision(2)<<a<<endl; else cout<<setiosfla...转载 2019-02-12 11:35:04 · 16514 阅读 · 0 评论 -
考试等级分级
Problem Description 期末考试结束了,老师想要根据学生们的成绩划分出等级。共有5个等级A,B,C,D和E。 划分方法如下,90分(含90)以上的为A,8090(含80)间的为B,7080(含70)间的为C, 60~70(含60)的为D,不及格的为E。 根据输入的成绩,编程输出各个级别段人数。 Input 输入第一行包含一个正整数N(N<= 100)代表学生的数目,接下来有N...原创 2019-02-15 22:11:59 · 1164 阅读 · 0 评论 -
简单计算
Problem Description 接受从键盘输入的N个整数,输出其中的最大值、最小值和平均值(平均值为整除的商)。 Input 第一行一个正整数N(N<=100); 第二行有N个用空格隔开的整数Ti (1 <= i <= N, 0 <= Ti <= 10000000) Output 三个有空格隔开的整数分别为最大值、最小值和平均值,其中平均值为整除的商。 Sam...原创 2019-02-15 21:52:04 · 285 阅读 · 0 评论 -
水仙花数
Problem Description 春天是鲜花的季节,水仙花就是其中最迷人的代表,数学上有个水仙花数,是这样定义的: “水仙花数”是指一个三位数,它的各位数字的立方和等于其本身,比如:153=13+53+33。 现在要求输出所有在m和n范围内的水仙花数。 Input 输入数据有多组,每组占一行,包括两个整数m和n(100<=m<=n<=999)。 Output 对于每个测试实...原创 2019-02-15 21:26:54 · 217 阅读 · 0 评论 -
分数序列
Problem Description 有一个分数序列:2/1, 3/2, 5/3, 8/5, 13/8, …编写程序求出这个序列的前n项之和。 Input 输入只有一个正整数n,1≤n≤10。 Output 输出该序列前n项和,结果保留小数后6位。 Sample Input 3 Sample Output 5.166667 Hint Source #include #include using ...原创 2019-02-15 18:30:14 · 237 阅读 · 0 评论 -
求绝对值最大值
Problem Description 求n个整数中的绝对值最大的数。 Input 输入数据有2行,第一行为n,第二行是n个整数。 Output 输出n个整数中绝对值最大的数。 Sample Input 5 -1 2 3 4 -5 Sample Output -5 Hint Source #include #include<math.h> using namespace std; in...原创 2019-02-15 18:24:02 · 2540 阅读 · 0 评论 -
数列求和
Problem Description 数列求和是一类常见的问题,本题有一定的代表性: 求s=a+aa+aaa+aaaa+……+aa…aa(n位) 其中,a的值由键盘输入,位数n也由键盘输入。 Input 第一行输入a的值; 第二行输入位数n。 Output 输出对n个数完成求和运算后的结果。 比如a=3,n=6时,s=3+33+333+3333+33333+333333 Sample Input...原创 2019-02-15 18:17:00 · 1228 阅读 · 0 评论 -
Input-Output Practice
Problem Description Your task is to Calculate the sum of some integers. Input Input contains multiple test cases. Each test case contains a integer N, and then N integers follow in the same line. A te...原创 2019-02-15 17:13:35 · 177 阅读 · 0 评论 -
圆周率计算
Problem Description 输入n值,并利用下列格里高里公式计算并输出圆周率: Input 输入公式中的n值。 Output 输出圆周率,保留5位小数。 Sample Input 1 Sample Output 2.66667 Hint Source #include #include using namespace std; int main(){ int n; double i,s...原创 2019-02-14 22:44:52 · 593 阅读 · 0 评论 -
最大公约数与最小公倍数
roblem Description 输入两个正整数,求它们的最大公约数与最小公倍数。 Input 输入两个正整数,两个整数之间用空格分开。 数据保证在 int 范围内。 Output 第一行输出最大公约数; 第二行输出最小公倍数。 答案保证在 int 范围内。 Sample Input 64 48 Sample Output 16 192 Hint Source #include using n...原创 2019-02-12 14:36:37 · 181 阅读 · 0 评论