简体   繁体   English

Hackerrank 上的测试用例失败

[英]Test Cases Failure on Hackerrank

For problem statement, I've attached two photos.对于问题陈述,我附上了两张照片。

https://i.stack.imgur.com/22zyM.png https://i.stack.imgur.com/22zyM.png

https://i.stack.imgur.com/5c8e6.png https://i.stack.imgur.com/5c8e6.png

My Code :我的代码:

for(i=0;i<300;i++)
{
    x[i]=i;y[i]=i;z[i]=i;
}

//printf("Enter number : "); 
scanf("%d",&n);
printf("%d\n",n);
//for(i=0;i<n;i++)
i=0;
do
{
    for(int j=0;j<n;j++)
    {
        for(int k=0;k<n;k++)
        {
            if(x[i]+y[j]+z[k]==n)
            {
                printf("%d %d %d \n",x[i],y[j],z[k]);
                i++;
            }
        }
    }
}while(i<n);

Now, the output that I'm getting for custom input values is correct for all values.现在,我为自定义输入值获得的输出对于所有值都是正确的。 But when I'm trying to check it for the test cases on the website it is showing correctly for only two cases.但是当我尝试检查网站上的测试用例时,它仅在两种情况下正确显示。

Link for problem statement : https://www.hackerrank.com/challenges/beautiful-3-set/problem?h_r=next-challenge&h_v=zen&isFullScreen=false问题陈述链接: https : //www.hackerrank.com/challenges/beautiful-3-set/problem?h_r=next-challenge&h_v=zen&isFullScreen=false

Please help me in solving this issue.请帮我解决这个问题。 Thanks.谢谢。

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

int n, k;

int main() {
scanf("%d", &n);
k = (2 * n) / 3;
printf("%d", k + 1);
printf("\n");
int y = 2 * k - n;
int x = n - 2 * y;
for (int i = 0; i <= y; i++) {
    printf("%d %d %d", i, x + i, n - x - 2 * i);
    printf("\n");
}
for (int i = 0; i < k - y; i++) {
    printf("%d %d %d", y + i + 1, i, n - y - 1 - 2 * i);
    printf("\n");
}
return 0;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM