全WA,但是本地输出和答案一样。
  • 板块P1781 宇宙总统
  • 楼主XNOR
  • 当前回复4
  • 已保存回复4
  • 发布时间2021/7/4 01:58
  • 上次更新2023/11/4 18:51:34
查看原帖
全WA,但是本地输出和答案一样。
415605
XNOR楼主2021/7/4 01:58

源代码:

#include <stdio.h>

int main(void)
{
	int n; scanf("%d", &n), getchar();

	static char str_1[100 + 1], str_2[100 + 1];

	int max = 1, max_length = 0, temp_length = 0;
	char* max_p = str_1, * temp_p = str_2,
		* max_c_p = max_p, * temp_c_p = temp_p;

	while ((*max_c_p = getchar()) != '\n') max_c_p++; *max_c_p = '\0';
	max_length = max_c_p - max_p;

	for (int i = 2; i <= n; i++)
	{
		for (temp_c_p = temp_p; (*temp_c_p = getchar()) != '\n'; temp_c_p++)
		{
			if (max_p[temp_c_p - temp_p] != *temp_c_p)
			{
				int flag = max_p[temp_c_p - temp_p] < *temp_c_p;

				while ((*++temp_c_p = getchar()) != '\n'); *temp_c_p = '\0';
				temp_length = temp_c_p - temp_p;

				if (flag && max_length <= temp_length || max_length < temp_length)
				{
					max = i, max_length = temp_length;
					char* swap = max_p; max_p = temp_p; temp_p = swap;
				}

				break;
			}
		}
	}

	printf("%d\n%s", max, max_p);

	return 0;
}
2021/7/4 01:58
加载中...