哎……又是 If平推字符
#include <bits/stdc++.h>
using namespace std;
signed main(){
char x;
while(cin>>x){
if(x=='1'){
cin>>x;
if(x=='1')cout<<">";
else if(x == '0'){
cin>>x;
if(x=='1')cout<<"]";
else if(x=='0')cout<<"-";
}
}else if (x=='0'){
cin>>x;
if(x=='1'){
cin>>x;
if(x=='1')cout<<"+";
else if(x=='0')cout<"[";
}else if(x=='0')
cout<<"<";
}
}
}
你也可以用map映射,当然也可以……
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
std::string s;
char c,ans=0;
while(std::cin>>c){
s+=c;
if(s=="010")ans='[';
else if(s=="101")ans= ']';
else if(s=="00")ans='<';
else if(s=="11")ans='>';
else if(s=="011")ans='+';
else if(s=="100")ans='-';
if(ans!=0){
std::cout<<ans;
s="",ans=0;
}
}
}