/ Vijos / 讨论 / C++ /

这题哪儿错了?!CF190C

CF界面AC了,怎么其他界面就错了?
代码:

#include<bits/stdc++.h>
using namespace std;
string ans;
int flag;
int x=0;
vector<string>s;
void dfs(){
    if(x>=(int)s.size()){
        cout<<"Error occurred";
        exit(0);
    }
    ans+=s[x];
    if(s[x]=="pair"){
        ans+='<';
        x++;
        dfs();
        ans+=',';
        x++;
        dfs();
        ans+='>';
        return;
    }
    else{
        return;
    }
}
int main(){
    int n;
    cin>>n;
    string str;
    cin.ignore();
    getline(cin,str);
    int z=0,y=0;
    str+=' ';
    for(int i=0;i<(int)str.size();i++){
        if(str[i]==' '){
            y=i-1;
            s.push_back(str.substr(z,y-z+1));
            z=i+1;
        }
    }
    if((int)s.size()==1&&s[0]=="int"){
        cout<<"int";
        return 0;
    }
    ans+=s[0];
    if(s[0]=="pair"){
        ans+='<';
        x++;
        dfs();
        ans+=',';
        x++;
        dfs();
        ans+='>';
    }
    else{
        cout<<"Error occurred";
        return 0;
    }
    if(x!=(int)s.size()-1){
        cout<<"Error occurred";
        return 0;
    }
    cout<<ans;
    return 0;
}

CF界面WA了的界面都在

1 条评论

  • 1