답안 #300476

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
300476 2020-09-17T07:53:49 Z Muhammetali 식물 비교 (IOI20_plants) C++11
컴파일 오류
0 ms 0 KB
#include "plants.h"
int res[10001];
int n;
void init(int k, std::vector<int> r) {
	n=sz(r);
	for (int i=0;i<sz(r);i++)res[i]=r[i];
	return;
}

int compare_plants(int x, int y) {
	bool b=0;
	int k=res[x];
	for (int i=x+1;i<y;i++)
	{
		if (res[i]!=k)
		{
			b=1;
			break;
		}
	}
	if (b==0)
	{
		if (k==0)return 1;
		else return -1;
	}
	b=0;
	k=res[y];
	while(y!=x)
	{
		if (res[y]!=k)
		{
			b=1;
			break;
		}
		y++;
		if (y==n)y=0;
	}
	if (!b)
	{
		if (k==1)return 1;
		else return -1;
	}
	return 0;
}#include "plants.h"
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
using namespace std;
int res[10001];
int n;
void init(int k, std::vector<int> r) {
	n=sz(r);
	for (int i=0;i<sz(r);i++)res[i]=r[i];
	return;
}

int compare_plants(int x, int y) {
	bool b=0;
	int k=res[x];
	for (int i=x+1;i<y;i++)
	{
		if (res[i]!=k)
		{
			b=1;
			break;
		}
	}
	if (b==0)
	{
		if (k==0)return 1;
		else return -1;
	}
	b=0;
	k=res[y];
	while(y!=x)
	{
		if (res[y]!=k)
		{
			b=1;
			break;
		}
		y++;
		if (y==n)y=0;
	}
	if (!b)
	{
		if (k==1)return 1;
		else return -1;
	}
	return 0;
}

Compilation message

plants.cpp:44:2: error: stray '#' in program
   44 | }#include "plants.h"
      |  ^
plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:5:4: error: 'sz' was not declared in this scope
    5 |  n=sz(r);
      |    ^~
plants.cpp:5:4: note: the macro 'sz' had not yet been defined
plants.cpp:46: note: it was later defined here
   46 | #define sz(x) (int)(x).size()
      | 
plants.cpp: At global scope:
plants.cpp:44:3: error: 'include' does not name a type
   44 | }#include "plants.h"
      |   ^~~~~~~
plants.cpp:48:5: error: redefinition of 'int res [10001]'
   48 | int res[10001];
      |     ^~~
plants.cpp:2:5: note: 'int res [10001]' previously declared here
    2 | int res[10001];
      |     ^~~
plants.cpp:49:5: error: redefinition of 'int n'
   49 | int n;
      |     ^
plants.cpp:3:5: note: 'int n' previously declared here
    3 | int n;
      |     ^
plants.cpp:50:6: error: redefinition of 'void init(int, std::vector<int>)'
   50 | void init(int k, std::vector<int> r) {
      |      ^~~~
plants.cpp:4:6: note: 'void init(int, std::vector<int>)' previously defined here
    4 | void init(int k, std::vector<int> r) {
      |      ^~~~
plants.cpp:56:5: error: redefinition of 'int compare_plants(int, int)'
   56 | int compare_plants(int x, int y) {
      |     ^~~~~~~~~~~~~~
plants.cpp:10:5: note: 'int compare_plants(int, int)' previously defined here
   10 | int compare_plants(int x, int y) {
      |     ^~~~~~~~~~~~~~