For problem statement, I've attached two photos.
https://i.stack.imgur.com/22zyM.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
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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.