谁能帮我看看这段代码是哪里出错了?谢谢

这是原题http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1760Aspartofanarithm... 这是原题
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1760
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<iostream>
using namespace std;
int main()
{
int a[100][15],b[100][15],sum,i,j,k,m,n,t[100];
i=0,m=0;
cin>>a[0][0];
while(a[m][0]!=-1)
{
while(a[m][i]!=0)
{
i=i+1;
cin>>a[m][i];
}
t[m]=i;
m=m+1;
cin>>a[m][0];
}
for(n=0;n<m;n=n+1)
{
sum=0;
for(j=0;j<t[n]-1;j=j+1)
b[n][j]=2*a[n][j];
for(j=0;j<t[n]-1;j=j+1)
{
for(k=0;k<t[n]-1;k=k+1)
{
if(b[n][j]==a[n][k])
sum=sum+1;
}
}
cout<<sum<<endl;
}
return(0);
}
我需要的不是代码
展开
 我来答
Alfred_H
2009-08-27 · TA获得超过1104个赞
知道小有建树答主
回答量:231
采纳率:0%
帮助的人:264万
展开全部
给你个代码,追点分吧

#include <iostream>
using namespace std;

void selectionSort(int A[], int size) {
for(int i = 0; i < size - 1; i++) {
int min = i;
for(int j = i + 1; j < size; j++)
if(A[j] < A[min]) min = j;
int temp = A[i];
A[i] = A[min];
A[min] = temp;
}
}

int main() {
int N, A[15];
while( cin >> A[N = 0] ) {
if( A[0] == -1 ) break;
while( cin >> A[++N] )
if( !A[N] ) break;
selectionSort( A, N );
int count = 0;
for( int i = 0; i < N - 1; i++ )
for( int j = i + 1; j < N; j++)
if( A[j] == A[i] * 2 )
count ++;
cout << count << endl;
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
AiPPT
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图... 点击进入详情页
本回答由AiPPT提供
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式