- C++
- @ 2026-06-13 10:46:22
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;
}
1 条评论
-
xiaogao LV 0 @ 2026-06-13 13:38:06
?
- 1