-2
昨天我解決問題SPOJ ABCD:http://www.spoj.com/problems/ABCD/SPOJ ABCD錯誤的答案
我得到錯誤的答案,但我實在想不通爲什麼。我已經在論壇和評論中嘗試過所有的測試用例。是否接受任何有效的解決方案或者是他們的文件中唯一有效的解決方案。
LOGIC:
- 計數各字符的出現在ROW1。
- 填充行2逐個檢查上字符的左邊的字符,也算< N.
我的代碼是:
#include<stdio.h>
int i;
int main()
{
int n;
int counts[4] = {0};
char row1[1000000], row2[1000000];
scanf("%d", &n);
scanf("%s", row1);
while(row1[i])
{
counts[row1[i] - 'A']++;
i++;
}
i = 0;
if(counts[0] < n && row1[i] != 'A')
{
row2[i] = 'A';
counts[0]++;
}
else if(counts[1] < n && row1[i] != 'B')
{
row2[i] = 'B';
counts[1]++;
}
else if(counts[2] < n && row1[i] != 'C')
{
row2[i] = 'C';
counts[2]++;
}
else
{
row2[i] = 'D';
counts[3]++;
}
i++;
while(i < (2 * n))
{
if(counts[0] < n && row1[i] != 'A' && row2[i - 1] != 'A')
{
row2[i] = 'A';
counts[0]++;
}
else if(counts[1] < n && row1[i] != 'B' && row2[i - 1] != 'B')
{
row2[i] = 'B';
counts[1]++;
}
else if(counts[2] < n && row1[i] != 'C' && row2[i - 1] != 'C')
{
row2[i] = 'C';
counts[2]++;
}
else
{
row2[i] = 'D';
counts[3]++;
}
i++;
}
row2[i] = '\0';
printf("%s", row2);
return 0;
}
我已經調試好幾個小時不知道該怎麼調試。 即使SPOJ論壇沒有找到我的解決方案。
Stack Overflow是不是一個調試器。尤其不適合學校比賽。 –