提出 #59397889


ソースコード 拡げる

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>

struct LIST {
	int data;  // 要素
	int num;  // 要素
	struct LIST* next; // 次のデータの場所(ポインタ)
};

static void swap(int* a, int* b)
{
	int temp;
	temp = *a;
	*a = *b;
	*b = temp;
}

void quick_sort(int* a, int get_left, int get_right)
{
	int left = get_left, right = get_right - 1, standard = get_right;
	if (left <= right)
	{
		while (left < right)
		{
			// 基準以下・以上の
			while (a[left] < a[standard] && left < right)
			{
				left++;
			}
			while (a[right] > a[standard] && left < right)
			{
				right--;
			}
			if (left < right)
			{
				swap(&a[left], &a[right]);
				left++;
				right--;
			}
		}

		if (a[left] < a[standard])
		{
			left += 1;
		}
		swap(&a[left], &a[standard]);

		quick_sort(a, get_left, left - 1);
		quick_sort(a, left + 1, get_right);
	}
}

int main(void) {
	int max_N = 100;
	int i, j, k;

	int N;

	struct LIST *root;
	root = (LIST*)malloc(sizeof(struct LIST));
	struct LIST* now;
	now = (LIST*)malloc(sizeof(struct LIST));
	struct LIST* p;
	p = (LIST*)malloc(sizeof(struct LIST));

	int* A = (int*)malloc(sizeof(int) * 200000);
	if (A == NULL) {
		return -1;
	}

	scanf("%d", &N);

	scanf("%d", &A[0]);
	root->data = A[0];
	root->num = 1;
	root->next = NULL;
	printf("-1");

	for (i = 1; i < N; i++)
	{
		printf(" ");

		now = root;
		scanf("%d", &A[i]);

		p->data;
		p->next = NULL;
		while (true)
		{
			if (A[i] == now->data)
			{
				printf("%d", now->num);
				now->num = i + 1;
				break;
			}
			else if (now->next == NULL)
			{
				printf("-1");
				p->data = A[i];
				p->num = i + 1;
				p->next = NULL;

				now->next = p;
				break;
			}
			else if (A[i] > now->next->data)
			{
				printf("-1");
				p->data = A[i];
				p->num = i + 1;
				p->next = now->next;

				now->next = p;
				break;
			}

			now = now->next;
		}
	}
	return 0;
}

提出情報

提出日時
問題 C - Repeating
ユーザ purazuma
言語 C (gcc 12.2.0)
得点 0
コード長 2020 Byte
結果 CE

コンパイルエラー

Main.c: In function ‘main’:
Main.c:61:17: error: ‘LIST’ undeclared (first use in this function)
   61 |         root = (LIST*)malloc(sizeof(struct LIST));
      |                 ^~~~
Main.c:61:17: note: each undeclared identifier is reported only once for each function it appears in
Main.c:61:22: error: expected expression before ‘)’ token
   61 |         root = (LIST*)malloc(sizeof(struct LIST));
      |                      ^
Main.c:63:21: error: expected expression before ‘)’ token
   63 |         now = (LIST*)malloc(sizeof(struct LIST));
      |                     ^
Main.c:65:19: error: expected expression before ‘)’ token
   65 |         p = (LIST*)malloc(sizeof(struct LIST));
      |                   ^
Main.c:89:24: error: ‘true’ undeclared (first use in this function)
   89 |                 while (true)
      |                        ^~~~
Main.c:4:1: note: ‘true’ is defined in header ‘<stdbool.h>’; did you forget to ‘#include <stdbool.h>’?
    3 | #include <stdlib.h>
  +++ |+#include <stdbool.h>
    4 | 
Main.c:72:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   72 |         scanf("%d", &N);
      |         ^~~~~~~~~~~~~~~
Main.c:74:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   74 |         scanf("%d", &A[0]);
      |         ^~~~~~~~~~~~~~~~~~
Main.c:85:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   85 |                 scanf("%d", &A[i]);
      |                 ^~~~~~~~~~~~~~~~~~