답안 #1003774

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1003774 2024-06-20T17:30:39 Z vjudge1 Zagrade (COI20_zagrade) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

int query( int a, int b ){
  cout << "? " << a << " " << b << endl;
  int x; cin >> x; return x;
}

int main(){
  int n, q; cin >> n >> q;
  stack<int> pilha;
  vector<int> resp(n + 1);
  for( int i = 1; i <= n; i++ ){
    if( pilha.empty() ){
      pilha.push(i);
      continue;
    }
    if( query( pilha.top(), i ) ){
      resp[i] = -1;
      resp[pilha.top()] = 1;
      pilha.pop();
    }
    else pilha.push(i);
  }
  int tam = pilha.size()/2;
  while(tam--){ resp[pilha.top()] = 1; pilha.pop(); }
  while(!pilha.empty()){ resp[pilha.top()] = -1; pilha.pop(); }
  cout << "! "
  for( int i = 1; i <= n; i++ ) cout << (( resp[i] == 1 ) ? "(" : ")" ); cout << endl;
}

Compilation message

zagrade.cpp: In function 'int main()':
zagrade.cpp:28:15: error: expected ';' before 'for'
   28 |   cout << "! "
      |               ^
      |               ;
   29 |   for( int i = 1; i <= n; i++ ) cout << (( resp[i] == 1 ) ? "(" : ")" ); cout << endl;
      |   ~~~          
zagrade.cpp:29:19: error: 'i' was not declared in this scope
   29 |   for( int i = 1; i <= n; i++ ) cout << (( resp[i] == 1 ) ? "(" : ")" ); cout << endl;
      |                   ^