URAL 1993 This cheeseburger you don't need
其实就是一个指定字符串的交换位置...还挺恶心的..写了很长不容易就贴一下吧...
各种拆分字符串,合并字符串...还有处理大小写...应该没什么trick
/********************* Template ************************/ #include <set> #include <map> #include <list> #include <cmath> #include <ctime> #include <deque> #include <queue> #include <stack> #include <bitset> #include <cstdio> #include <string> #include <vector> #include <cassert> #include <cstdlib> #include <cstring> #include <sstream> #include <fstream> #include <numeric> #include <iomanip> #include <iostream> #include <algorithm> #include <functional> using namespace std; #define EPS 1e-8 #define DINF 1e15 #define MAXN 100050 #define MOD 1000000007 #define INF 0x7fffffff #define LINF 1LL<<60 #define PI 3.14159265358979323846 #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define BUG cout<<" BUG! "<<endl; #define LINE cout<<" ------------------ "<<endl; #define FIN freopen("in.txt","r",stdin); #define FOUT freopen("out.txt","w",stdout); #define mem(a,b) memset(a,b,sizeof(a)) #define FOR(i,a,b) for(int i = a ; i < b ; i++) #define read(a) scanf("%d",&a) #define read2(a,b) scanf("%d%d",&a,&b) #define read3(a,b,c) scanf("%d%d%d",&a,&b,&c) #define write(a) printf("%d\n",a) #define write2(a,b) printf("%d %d\n",a,b) #define write3(a,b,c) printf("%d %d %d\n",a,b,c) #pragma comment (linker,"/STACK:102400000,102400000") template<class T> inline T L(T a) {return (a << 1);} template<class T> inline T R(T a) {return (a << 1 | 1);} template<class T> inline T lowbit(T a) {return (a & -a);} template<class T> inline T Mid(T a,T b) {return ((a + b) >> 1);} template<class T> inline T gcd(T a,T b) {return b ? gcd(b,a%b) : a;} template<class T> inline T lcm(T a,T b) {return a / gcd(a,b) * b;} template<class T> inline T ABS(T a) {return a > 0 ? a : -a;} template<class T> inline T Min(T a,T b) {return a < b ? a : b;} template<class T> inline T Max(T a,T b) {return a > b ? a : b;} template<class T> inline T Min(T a,T b,T c) {return min(min(a,b),c);} template<class T> inline T Max(T a,T b,T c) {return max(max(a,b),c);} template<class T> inline T Min(T a,T b,T c,T d) {return min(min(a,b),min(c,d));} template<class T> inline T Max(T a,T b,T c,T d) {return max(max(a,b),max(c,d));} template<class T> inline T exGCD(T a, T b, T &x, T &y){ if(!b) return x = 1,y = 0,a; T res = exGCD(b,a%b,x,y),tmp = x; x = y,y = tmp - (a / b) * y; return res; } template<class T> inline T reverse_bits(T x){ x = (x >> 1 & 0x55555555) | ((x << 1) & 0xaaaaaaaa); x = ((x >> 2) & 0x33333333) | ((x << 2) & 0xcccccccc); x = (x >> 4 & 0x0f0f0f0f) | ((x << 4) & 0xf0f0f0f0); x = ((x >> 8) & 0x00ff00ff) | ((x << 8) & 0xff00ff00); x = (x >>16 & 0x0000ffff) | ((x <<16) & 0xffff0000); return x; } //typedef long long LL; typedef unsigned long long ULL; //typedef __int64 LL; typedef unsigned __int64 ULL; /********************* By F *********************/ string str; string obj[105],sub[105],verb[105]; int cnt1 = 0 ,cnt2 = 0 ,cnt3 = 0 ; int len; void divide(){ for(int i = 0 ; i < len ; i++){ if(str[i] == '('){ for(int j = i+1 ; j < len ; j++){ if(str[j] == ')'){ sub[cnt1++] = str.substr(i+1,j-i-1); break; } } } } for(int i = 0 ; i < len ; i++){ if(str[i] == '['){ for(int j = i+1 ; j < len ; j++){ if(str[j] == ']'){ verb[cnt2++] = str.substr(i+1,j-i-1); break; } } } } for(int i = 0 ; i < len ; i++){ if(str[i] == '{'){ for(int j = i+1 ; j < len ; j++){ if(str[j] == '}'){ obj[cnt3++] = str.substr(i+1,j-i-1); break; } } } } } int main(){ //FIN; while(getline(cin,str)){ len = str.size(); cnt1 = 0 ,cnt2 = 0 ,cnt3 = 0; for(int i = 0 ; i < len ; i++){ if(str[i] >= 'A' && str[i] <= 'Z') { str[i] = str[i] - 'A' + 'a'; break; } } string ssub[105]; int cnt = 0; for(int i = 0 ; i < len ; i++){ //cout<<i<<endl; if(str[i] == '(' || str[i] == '{' || str[i] == '['){ for(int j = i+1 ; j < len ; j++){ if(str[j] == ')' || str[j] == ']' || str[j] == '}'){ ssub[cnt++] = str.substr(i,j-i+1); //cout<<sub[cnt-1]<<endl; i = j; break; } } }else{ for(int j = i+1 ; j < len ; j++){ if(str[j] == '(' || str[j] == '{' || str[j] == '['){ ssub[cnt++] = str.substr(i,j-i); //cout<<sub[cnt-1]<<endl; i = j-1; break; } } } } divide(); int flag = 0,c = 0; string res; for(int i = 0 ; i < cnt ; i++){ if(ssub[i][0] == '(' || ssub[i][0] == '{' || ssub[i][0] == '[' ){ if(flag == 0) res+=obj[c]; else if(flag == 1) res+=sub[c]; else if(flag == 2) res+=verb[c]; if(++flag == 3){ flag = 0; c++; } }else res+=ssub[i]; } if(res[0] >= 'a' && res[0] <= 'z') res[0] = res[0] - 'a' + 'A'; cout<<res<<endl; } return 0; }