![](/img/trans.png)
[英]What is my C code not printing # in staircase pattern, this is from hackerrank, I did not pass all test cases, but i can't point out why?
[英]Test Cases Failure on Hackerrank
對於問題陳述,我附上了兩張照片。
https://i.stack.imgur.com/22zyM.png
https://i.stack.imgur.com/5c8e6.png
我的代碼:
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);
現在,我為自定義輸入值獲得的輸出對於所有值都是正確的。 但是當我嘗試檢查網站上的測試用例時,它僅在兩種情況下正確顯示。
問題陳述鏈接: https : //www.hackerrank.com/challenges/beautiful-3-set/problem?h_r=next-challenge&h_v=zen&isFullScreen=false
請幫我解決這個問題。 謝謝。
#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.