Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
199 views
in Technique[技术] by (71.8m points)

c - Online judgeProblem (Wrong Answer)

problem in Light OJ: 1001 - Opposite Task:

This problem gives you a flavor the concept of special judge. That means the judge is smart enough to verify your code even though it may print different results. In this problem you are asked to find the opposite task of the previous problem.

To be specific, I have two computers where I stored my problems. Now I know the total number of problems is n. And there are no duplicate problems and there can be at most 10 problems in each computer. You have to find the number of problems in each of the computers.

Since there can be multiple solutions. Any valid solution will do.

Input: Input starts with an integer T (≤ 25), denoting the number of test cases.

Each case starts with a line containing an integer n (0 ≤ n ≤ 20) denoting the total number of problems.

Output: For each case, print the number of problems stored in each computer in a single line. A single space should separate the non-negative integers. Sample Input

Output for Sample Input:

3
10
7
7

Sample output:

0(space)10

0(space)7

1(space)6

my code :

#include<stdio.h>
#include <stdlib.h>
int main()
{
 int c,sum;
 int i,j,mini=0,maxi;
 int com1,com2;

 do{
     scanf("%d",&c);
 }while (c>25);
 int t[c+1];

 for(i=1; i<=c; i++)
 {
    do{
        scanf("%d",&t[i]);
    }while (t[i]>20);
 }

 for(i=1; i<=c; i++)
 {
    maxi=t[i];
    com1=rand() % (maxi - mini + 1) + mini;
    com2=t[i]-com1;
    printf("%d %d
",com1,com2);

 }
 return 0;
}

When I submit my code the judge gives wrong answer. But while I compile the code in CodeBlocks it gives right answer. I can't understand the problem in online judge. How can I solve it.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The original post has mini=0 for all cases, but where the total problems is > 10 that may not work. I have adjusted that

#include<stdio.h>
#include <stdlib.h>

int main()
{
int c = 0, mini, maxi, i, com1, com2, *t;
scanf ("%d",&c);
t = malloc (c * sizeof(int));
for (i=0; i<c; i++)
    scanf ("%d", &t[i]);
printf("
");        

for (i=0; i<c; i++) {
    if (t[i]>10) {
        maxi = 10;
        mini = t[i] - 10;
    } else {
        maxi = t[i];
        mini = 0;
    }
    com1 = rand() % (maxi - mini + 1) + mini;
    com2 = t[i] - com1;
    printf("%d %d
",com1,com2);        
    }
free (t);
return 0;
}

Please note that results of malloc() and scanf() have not been checked: they should be.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...