답안 #16482

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
16482 2015-08-26T11:19:38 Z who7117 로봇 심판의 님 게임 (kriii3_F) C
컴파일 오류
0 ms 0 KB
#include<stdio.h>
#include<stdlib.h>

void main()
{
	int N, M, K;
	int *p, *q, *k;
	int bot = 0, top = 0, toggle = 0;
	// bot = 구슬 가장 적게 꺼낸 뒤 주머니 구슬의 수
	// top = 이기기 위해 꺼내는 구슬의 수

	// 1 <= N,M		N+M <= 16		1 <= K <= 20
	// N,M : 주머니를 검사하는 조건의 개수
	// K : 처음 주머니의 개수
	scanf("%d %d %d", &N, &M, &K);
	p = (int*)malloc(sizeof(int)*N);
	q = (int*)malloc(sizeof(int)*M);
	k = (int*)malloc(sizeof(int)*K);

	for (int i = 0; i < N; i++)
		scanf("%d", &p[i]);
	for (int i = 0; i < M; i++)
		scanf("%d", &q[i]);
	for (int i = 0; i < K; i++)
		scanf("%d", &k[i]);

	for (int y = 0; y < K; y++)
	{
		top = 0; bot = 0;
		for (k[y]--; k[y] > 0 && toggle == 0; k[y]--)
			top++;

			for (int i = 0; (i < N) && (toggle == 0); i++)
				if (k[y] % p[i] == 0)
					toggle = 1;

			for (int i = 0; (i < M) && (toggle == 0); i++)
				if (k[y] % q[i] != 0)
					toggle = 1;
		}
		if (toggle == 1)
		{
			bot = k[y] + 1;
			toggle = 0;
		}
		if (bot == 0)
			printf("0 0\n");
		else
			printf("%d %d\n", top, bot);
	}
}

Compilation message

S.c:4:6: warning: return type of ‘main’ is not ‘int’ [-Wmain]
 void main()
      ^
S.c: In function ‘main’:
S.c:20:2: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
  for (int i = 0; i < N; i++)
  ^
S.c:20:2: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code
S.c:22:11: error: redefinition of ‘i’
  for (int i = 0; i < M; i++)
           ^
S.c:20:11: note: previous definition of ‘i’ was here
  for (int i = 0; i < N; i++)
           ^
S.c:22:2: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
  for (int i = 0; i < M; i++)
  ^
S.c:24:11: error: redefinition of ‘i’
  for (int i = 0; i < K; i++)
           ^
S.c:22:11: note: previous definition of ‘i’ was here
  for (int i = 0; i < M; i++)
           ^
S.c:24:2: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
  for (int i = 0; i < K; i++)
  ^
S.c:27:2: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
  for (int y = 0; y < K; y++)
  ^
S.c:33:4: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
    for (int i = 0; (i < N) && (toggle == 0); i++)
    ^
S.c:37:13: error: redefinition of ‘i’
    for (int i = 0; (i < M) && (toggle == 0); i++)
             ^
S.c:33:13: note: previous definition of ‘i’ was here
    for (int i = 0; (i < N) && (toggle == 0); i++)
             ^
S.c:37:4: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
    for (int i = 0; (i < M) && (toggle == 0); i++)
    ^
S.c: At top level:
S.c:51:1: error: expected identifier or ‘(’ before ‘}’ token
 }
 ^
S.c: In function ‘main’:
S.c:15:2: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d", &N, &M, &K);
  ^
S.c:21:3: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &p[i]);
   ^
S.c:23:3: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &q[i]);
   ^
S.c:25:3: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &k[i]);
   ^