山东理工大学ACM平台题答案关于C语言 1075 Doubles

Doubles

Time Limit: 1000ms   Memory limit: 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
 
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.

输入

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.

输出

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
2 4 8 10 0
7 5 11 13 1 3 0
-1

示例输出

3
2
0

双打

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

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.

你的程序应该回答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

1 4 3 2 9 7 18 22 0

2 4 8 10 0

2 4 8 10 0

7 5 11 13 1 3 0

7 5 11 13 1 3 0

-1示例输出

1示例输出

3

3

2

2

0

0

#include <stdio.h>

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<a_num; i++)

                for (j=0; j<a_num; j++)

                    if (i!=j && a[i]==a[j]*2)

                        count++;

            printf("%d\n", count);

            a_num = 0;

            count = 0;

        }

    }

    

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值