一道简单的acm题目中的一个bug求调试DescriptionAs 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 ar

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/02 13:17:44
一道简单的acm题目中的一个bug求调试DescriptionAs 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 ar

一道简单的acm题目中的一个bug求调试DescriptionAs 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 ar
一道简单的acm题目中的一个bug求调试
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 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 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.
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
我写的程序是这样的:
#include
#include
int *a;
int length;
void output()
{
\x05for(int i = 0 ; i < length ; i ++)
\x05\x05printf("%d\n",a[i]);
}
int input()
{
\x05int temp;
\x05scanf("%d",&temp);
\x05for(length = 1 ; temp!=0 ; length++)
\x05{
\x05\x05if(a)
\x05\x05{
\x05\x05\x05a=(int *)realloc(a,sizeof(int)*length);
\x05\x05}
\x05\x05else
\x05\x05{
\x05\x05\x05a=(int *)malloc(sizeof(int));
\x05\x05}
\x05\x05a[length-1]=temp;
\x05\x05scanf("%d",&temp);
\x05}
\x05return a[0];
}
int solve()
{
\x05int count = 0,max = a[0];
\x05//首先查找最大值
\x05for(int i = 1 ; i< length ; i++)
\x05{
\x05\x05if(max < a[i])
\x05\x05\x05max = a[i];
\x05}
\x05for(int i = 0 ; i < length ; i++)
\x05{
\x05\x05for(int j = 0 ; j < length ; j++)
\x05\x05{
\x05\x05\x05if(a[i]

一道简单的acm题目中的一个bug求调试DescriptionAs 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 ar

总共最多15个数,为啥要动态分配内存啊

void initialise()
{
free(a);
a = NULL; // 释放完你还不赶紧把a设为NULL
length = 1;
}

一道简单的acm题目中的一个bug求调试DescriptionAs 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 ar 一道简单的数学分析题目,求帮忙! 杭电acm 2034wrong answer Problem Description参加过上个月月赛的同学一定还记得其中的一个最简单的题目,就是{A}+{B},那个题目求的是两个集合的并集,今天我们这个A-B求的是两个集合的差,就是做集合 一道简单的题目 一道简单的题目 求助一道ACM题一道很简单的ACM题目,题在这里我写的代码如下:#include using namespace std;int main(){int n,m[30];cin>>n;for(int i=0;i=0;j--){cout 很简单的一道求极限的题目,实在太蠢啦,> 一道简单的高中政治题目 一道简单的二重积分题目 ...一道简单的曲线运动题目 200分 出一道关与成语很简单的题!用目不识丁.目不见睫.目不窥园.目无全牛.四个成语中的一个或几个出一道辩析成语的题目上课用.不求质量.越快越好. 一道简单的数学题目因式分解,求解答,谢谢老师! 一道简单的求定积分题目.r为常数 一个圆环的外径是4acm,内径是2acm,求这个圆环的面积? 一个等腰三角形底边长是acm,腰长是3acm,求它的周长为多少cm 求简单的一个英语口语对话题目为电影、歌手、演员、书、宠物中的随便一个,要求对话6次 求win-TC 完备数的代码要比较简单的,最好调试过 ACM rightmost digit 求简单思路求简单思路