4个都是WA,但是下载数据在vs2019上调试结果正确,求助
查看原帖
4个都是WA,但是下载数据在vs2019上调试结果正确,求助
590283
lunatics楼主2022/1/23 17:32
#include<stdio.h>
int main(void)
{
	int i, j, N, count, carry = 0, flag = 1;
	char ch, num[130] = { 0 }, result[130] = { 0 };
	scanf("%d", &N);
	getchar();
	for (i=0;(ch = getchar()) != '\n';i++)
		num[i] = ch;
	for (count = 1; count <= 30; count++)
	{
		for (j = i - 1; j >= 0; j--)
		{
			if (num[j] + num[i - j - 1] + carry >= 96 + N)
			{
				result[j] = '0' + (num[j] + num[i - j - 1] + carry - 96 - N);
				carry = 1;
			}
			else
			{
				result[j] = '0' + (num[j] + num[i - j - 1] + carry - 96);
				carry = 0;
			}
		}
		if (carry == 1)
		{
			for (j = i; j > 0; j--)
				result[j] = result[j - 1];
			result[0] = '1';
			i = i + 1;
		}
		for (j = 0; j < i; j++)
		{
			if (result[j] != result[i - j - 1])
				flag = 0;
		}
		if (flag == 1)
			break;
		for (i = 0; result[i] != '\0'; i++)
			num[i] = result[i];
		carry = 0;
		flag = 1;
	}
	if (count <= 30)
		printf("STEP=%d", count);
	else
		printf("Impossible!");
	return 0;
}
2022/1/23 17:32
加载中...