pku_1552 Doubles 解题报告
2009-02-27 22:17
295 查看
Description
As part of an arithmetic competency program, your students will be given randomly generated lists of from 2 to 15 unique positive integers and asked to determine how many items in each list are twice some other item in the same list. You will need a program to help you with the grading. This program should be able to scan the lists and output the correct answer for each one. For example, given the list
your program should answer 3, as 2 is twice 1, 4 is twice 2, and 18 is twice 9.
Input
The input will consist of one or more lists of numbers. There will be one list of numbers per line. Each list will contain from 2 to 15 unique positive integers. No integer will be larger than 99. Each line will be terminated with the integer 0, which is not considered part of the list. A line with the single number -1 will mark the end of the file. The example input below shows 3 separate lists. Some lists may not contain any doubles.
Output
The output will consist of one line per input list, containing a count of the items that are double some other item.
Sample Input
Sample Output
As part of an arithmetic competency program, your students will be given randomly generated lists of from 2 to 15 unique positive integers and asked to determine how many items in each list are twice some other item in the same list. You will need a program to help you with the grading. This program should be able to scan the lists and output the correct answer for each one. For example, given the list
1 4 3 2 9 7 18 22
your program should answer 3, as 2 is twice 1, 4 is twice 2, and 18 is twice 9.
Input
The input will consist of one or more lists of numbers. There will be one list of numbers per line. Each list will contain from 2 to 15 unique positive integers. No integer will be larger than 99. Each line will be terminated with the integer 0, which is not considered part of the list. A line with the single number -1 will mark the end of the file. The example input below shows 3 separate lists. Some lists may not contain any doubles.
Output
The output will consist of one line per input list, containing a count of the items that are double some other item.
Sample Input
1 4 3 2 9 7 18 22 0 2 4 8 10 0 7 5 11 13 1 3 0 -1
Sample Output
3 2 0
/* * File: pku_1552.cpp * Author: Killua * * Created on 2009��2��27�� */ #include <iostream> #include<algorithm> using namespace std; /* * */ int num[20]; int n; int countDouble() { int i, j; int count = 0; for (i = 0; i < n; i++) for (j = i + 1; j < n; j++) if (num[j] == num[i]*2) { count++; break; } return count; } int main(int argc, char** argv) { int x; int count; while (1) { n = 0; while (cin >> x) { if (!x) break; if (x == -1) return 0; num[n++] = x; } sort(num,num+n); count=countDouble(); cout<<count<<endl; } return (EXIT_SUCCESS); }[/code]
key:水题...刷着...
相关文章推荐
- PKU1061 解题报告 青蛙的约会 __用扩展欧几里得解模同余方程
- PKU1737 解题报告 Connected Graph __高精度加法,乘法,减法,组合数
- pku 1222 EXTENDED LIGHTS OUT 解题报告 之高斯消去法
- pku 树形dp 1849 two 解题报告
- pku 2411 modriaans dream 压缩dp 解题报告
- pku 1521 赫夫曼编码 Entropy 解题报告
- pku 1001 高精度 Exponentiation 解题报告
- pku 1953 dp World Cup Noise 解题报告
- pku 2533 最长递增子序列 Longest Ordered Subsequence 解题报告
- pku acm 2021题解题报告
- hdu 1102 pku 2421 解题报告
- Pku acm 1157 LITTLE SHOP OF FLOWERS 动态规划题目解题报告(十四)
- Pku acm 1423 Big Number 解题报告----求n!的位数
- Pku acm 1274 The Perfect Stall 数据结构题目解题报告(十三)---- 匈牙利算法求二分图的最大匹配
- Pku acm 2406 Power Strings数据结构题目解题报告(十八)----kmp算法
- acm pku 2234 解题报告(取子问题)
- ACM pku 1003 解题报告(练习输入输出)
- 单调队列 - 兼 ACM PKU POJ 3250 及 2823 解题报告 [转]
- pku1160 Post Office 解题报告
- PKU 1552 Doubles