QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#215684#5108. Prehistoric ProgramsYYYYYYYYCompile Error//C++141.7kb2023-10-15 12:46:282023-10-15 12:46:29

Judging History

你现在查看的是最新测评结果

  • [2023-10-15 12:46:29]
  • 评测
  • [2023-10-15 12:46:28]
  • 提交

answer

#include <iostream>
#include <cstring>
#include<string> 
#include <vector>
#include <algorithm>

int main() {
    int n = 0;
    std::string parentheses;
    std::cin >> n;
    int sum = 0;
	std::vector<std::vector<int>> in(n, std::vector<int>(3, 0));
	// std::cin.tie(NULL);

    for (int i = 0; i < n; i++) {
        std::cin >> parentheses;
		int par = 0;
		in[i][2]=i+1;
        for (char ch : parentheses) {
            if (ch == '(') {
                open_count++;
            } else if (ch == ')') {
                if (open_count > 0) {
                    open_count--;
                } else {
                    close_count++;
                }
            }
        }

        in[i][0] = open_count;
        in[i][1] = close_count;
    }
    }
    

    
  
    std::sort(in.begin(), in.end(), [](const std::vector<int>& a, const std::vector<int>& b){
		
		int con1 = (a[0] == a[1] ? 0 : (a[0] > a[1] ? 1 : -1));
        int con2 = (b[0] == b[1] ? 0 : (b[0] > b[1] ? 1 : -1));
        //more'('=1, more')'=-1, else 0
        if (con1 != con2) return con1 > con2;
        //return the one with more '('
        if (con1 == 1) return a[1] < b[1];
        //retuen the one with less ')'
        else return a[0] > b[0];
		//return the one with more'('
    });
	

	//v[i] = left+v+right
    sum = 0;
	// std::cout<<"left"<<left[0]<<"right"<<right[0];
    for(int i = 0; i < in.size(); i++){
        sum -= in[i][1];
        if(sum<0){
            std::cout<<"impossible"; 
    	    return 0;
        }
        sum+=in[i][0];
    }
	if(sum!=0){
    	std::cout<<"impossible";
    	return 0;
	}
	for (int i = 0; i < in.size(); i++) {
		std::cout << in[i][2] << " ";
	}
	
    return 0;
}


Details

answer.code: In function ‘int main()’:
answer.code:21:17: error: ‘open_count’ was not declared in this scope
   21 |                 open_count++;
      |                 ^~~~~~~~~~
answer.code:23:21: error: ‘open_count’ was not declared in this scope
   23 |                 if (open_count > 0) {
      |                     ^~~~~~~~~~
answer.code:26:21: error: ‘close_count’ was not declared in this scope
   26 |                     close_count++;
      |                     ^~~~~~~~~~~
answer.code:31:20: error: ‘open_count’ was not declared in this scope
   31 |         in[i][0] = open_count;
      |                    ^~~~~~~~~~
answer.code:32:20: error: ‘close_count’ was not declared in this scope
   32 |         in[i][1] = close_count;
      |                    ^~~~~~~~~~~
answer.code: At global scope:
answer.code:39:14: error: expected constructor, destructor, or type conversion before ‘(’ token
   39 |     std::sort(in.begin(), in.end(), [](const std::vector<int>& a, const std::vector<int>& b){
      |              ^
answer.code:50:6: error: expected unqualified-id before ‘)’ token
   50 |     });
      |      ^
answer.code:54:5: error: ‘sum’ does not name a type
   54 |     sum = 0;
      |     ^~~
answer.code:56:5: error: expected unqualified-id before ‘for’
   56 |     for(int i = 0; i < in.size(); i++){
      |     ^~~
answer.code:56:20: error: ‘i’ does not name a type
   56 |     for(int i = 0; i < in.size(); i++){
      |                    ^
answer.code:56:35: error: ‘i’ does not name a type
   56 |     for(int i = 0; i < in.size(); i++){
      |                                   ^
answer.code:64:9: error: expected unqualified-id before ‘if’
   64 |         if(sum!=0){
      |         ^~
answer.code:68:9: error: expected unqualified-id before ‘for’
   68 |         for (int i = 0; i < in.size(); i++) {
      |         ^~~
answer.code:68:25: error: ‘i’ does not name a type
   68 |         for (int i = 0; i < in.size(); i++) {
      |                         ^
answer.code:68:40: error: ‘i’ does not name a type
   68 |         for (int i = 0; i < in.size(); i++) {
      |                                        ^
answer.code:72:5: error: expected unqualified-id before ‘return’
   72 |     return 0;
      |     ^~~~~~
answer.code:73:1: error: expected declaration before ‘}’ token
   73 | }
      | ^