2345_Gold Coins(输入分多个块,每个块中有多行,每个输入块之间有空格,但最后没有空格)
2013-04-21 23:18
399 查看
The king pays his loyal knight in gold coins. On the first day of his service, the knight receives one gold coin. On each of the next two days (the second and third days of service), the knight receives two gold coins. On each of the next three days (the
fourth, fifth, and sixth days of service), the knight receives three gold coins. On each of the next four days (the seventh, eighth, ninth, and tenth days of service), the knight receives four gold coins. This pattern of payments will continue indefinitely:
after receiving N gold coins on each of N consecutive days, the knight will receiveN+1 gold coins on each of the nextN+1 consecutive days, where
N is any positive integer.
Your program will determine the total number of gold coins paid to the knight in any given number of days (starting from Day 1).
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
Input
Each input block contains at least one, but no more than 21 lines. Each line of the input (except the last one) contains data for one test case of the problem, consisting of exactly one integer (in the range 1..10000), representing the number of days. The
end of the input is signaled by a line containing the number 0.
Output
There is exactly one line of output for each test case. This line contains the number of days from the corresponding line of input, followed by one blank space and the total number of gold coins paid to the knight in the given number of days, starting with
Day 1.
Sample Input
1
10
6
7
11
15
16
100
10000
1000
21
22
0
Sample Output
10 30
6 14
7 18
11 35
15 55
16 61
100 945
10000 942820
1000 29820
21 91
22 98
Source: Rocky Mountain 2004
fourth, fifth, and sixth days of service), the knight receives three gold coins. On each of the next four days (the seventh, eighth, ninth, and tenth days of service), the knight receives four gold coins. This pattern of payments will continue indefinitely:
after receiving N gold coins on each of N consecutive days, the knight will receiveN+1 gold coins on each of the nextN+1 consecutive days, where
N is any positive integer.
Your program will determine the total number of gold coins paid to the knight in any given number of days (starting from Day 1).
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
Input
Each input block contains at least one, but no more than 21 lines. Each line of the input (except the last one) contains data for one test case of the problem, consisting of exactly one integer (in the range 1..10000), representing the number of days. The
end of the input is signaled by a line containing the number 0.
Output
There is exactly one line of output for each test case. This line contains the number of days from the corresponding line of input, followed by one blank space and the total number of gold coins paid to the knight in the given number of days, starting with
Day 1.
Sample Input
1
10
6
7
11
15
16
100
10000
1000
21
22
0
Sample Output
10 30
6 14
7 18
11 35
15 55
16 61
100 945
10000 942820
1000 29820
21 91
22 98
Source: Rocky Mountain 2004
//第一天给一块,然后两天各给两块,然后三天各给三块,输入天数,求块数 //输入输出很讲究,输入分多个块,每个块中有多行,每个输入块之间有空格,但最后没有空格。 #include<iostream> using namespace std; int main() { int day,coin; int i,j,dd; int num;//块号 cin>>num; while(num--) { while(cin>>day&&day) { if(day==0) break; dd=i=coin=0; while(dd<day) { i++; dd+=i; } dd-=i; for(j=1;j!=i;j++) coin+=j*j; coin+=(day-dd)*i; cout<<day<<" "<<coin<<endl; } if(num!=0)//每个输入块之间有空格,但最后没有空格 cout<<endl; } return 0; }
相关文章推荐
- 输入两手牌,两手牌之间用“-”连接,每手牌的每张牌以空格分隔,“-”两边没有空格,如:4 4 4 4-joker JOKER 请比较两手牌大小,输出较大的牌,如果不存在比较关系则输出ERROR
- 输入包括两行,第一行是一个正整数N(N<=1000000),表示理工大共N个美女。第二行有N个正整数分别表示N位美女的身高,每个正整数的值不会超过10^9。 (输入数据之间会用空格隔开)
- 输入包括两行,第一行是一个正整数N(N<=1000000),表示理工大共N个美女。第二行有N个正整数分别表示N位美女的身高,每个正整数的值不会超过10^9。 (输入数据之间会用空格隔开)
- 输入包括两行,第一行是一个正整数N(N<=1000000),表示理工大共N个美女。第二行有N个正整数分别表示N位美女的身高,每个正整数的值不会超过10^9。 (输入数据之间会用空格隔开)
- 输入一行字符,统计其中有多少个单词,单词之间用空格隔开
- 输入n,打印1到n之间的每个数,考虑整数溢出
- 编写一个程序,删除每个输入行末尾的换行符和制表符,并删除完全是空格或制表符的行<The C Programming Language>课后习题
- 输入一行字符,统计其中有多少个单词,单词之间用空格分隔开。
- 把字符串中的每个空格替换程“%20”,例如输入“I love my hometown”,输出为”I%20love%20my%20hometown”
- 实现一个函数,把字符数组中的每个空格替换成“%20”。 例如输入“we are happy.”,则输出“we%20are%20happy”
- 输入一行字符,统计其中的单词的个数.各单词之间用空格分隔
- 把字符串中的每个空格替换程“%20”,例如输入“I love my hometown”,输出为”I%20love%20my%20hometown”
- 给定一个句子(只包含字母和空格), 将句子中的单词位置反转,单词用空格分割, 单词之间只有一个空格,前后没有空格。
- 输入一行字符,统计其中有多少个单词,单词之间用空格隔开
- 【我的算法日记】请实现一个函数,把字符串中的每个空格替换成“%20”。例如输入“We are happy.”,则输出“We%20are%20happy.”。
- 从一个名为 in_file.txt 的文本文件中读取单词,然后把每个词写到一个名为out_file.txt的输出文件中 并且每个词之间用空格分开
- 在两组内容之间输出空行(意思就是在最后一行时只有一个换行而没有空行)
- Problem Description 求n个数的最小公倍数。 Input 输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数。 Output 为每组测试数据输出它们的最小公倍数,每个测试实例的输出占一行。你可以假设最后的输出是一个32位的整数。 Sample
- 已知: 每个飞机只有一个油箱, 飞机之间可以相互加油(注意是相互,没有加油机) 一箱油可供一架飞机绕地球飞半圈,问题:为使至少一架飞机绕地球一圈回到起飞时的飞机
- 把字符串中的每个空格替换程“%20”,例如输入“I love my hometown”,输出为”I%20love%20my%20hometown”