双打
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
时间限制:1000MS内存限制:65536k有疑问点这里^_^?
题目描述
题目描述
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
作为一个算术能力计划的一部分,你的学生将获得随机生成的列表,从2到15个独特的正整数,要求确定每个列表中有多少项两次其他一些项目在同一个列表。你需要一个程序来帮助你分级。这个程序会扫描列表和输出的每一个正确的答案。例如,给定的列表
1 4 3 2 9 7 18 22
1432971822
your program should answer 3, as 2 is twice 1, 4 is twice 2, and 18 is twice 9.
你的程序应该回答3,2是1的两倍,4是2的两倍,18是9的两倍。
输入
输入
The input file 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.
输入文件将包含一个或更多的数字列表。会有一个列表,每行数。每个列表将包含2到15个独特的正整数。没有将大于99的整数。每一条线将与整数0终止,这是不被认为是列表的一部分。一条线与单编号1将标记文件的结尾。输入下面的例子显示了3个独立的列表。某些列表可能不包含任何双打。
输出
输出
The output will consist of one line per input list, containing a count of the items that are double some other item.
输出将包括每行输入清单,包含一个数,双重其他一些项目的项目。
示例输入
示例输入
1 4 3 2 9 7 18 22 0
14329718220
2 4 8 10 0
248100
7 5 11 13 1 3 0
751113130
-1示例输出
1示例输出
3
3
2
2
0
0
#include
void main()
{
int t, a[15], a_num, i, j, count;
a_num = 0;
count = 0;
while (1)
{
scanf("%d", &t);
if (t == -1) break;
if (t != 0)
{
a[a_num++] = t;
}
else
{
for (i=0; i
for (j=0; j
if (i!=j && a[i]==a[j]*2)
count++;
printf("%d\n", count);
a_num = 0;
count = 0;
}
}
}