Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
大家速度来围观,cin+stl string=960MS。。。。。贴代码,这个效率我不说了Source Code Problem: 1635 User: yzhw Memory: 824K Time: 969MS Language: G++ Result: Accepted Source Code # include <iostream> using namespace std; # include <string> # include <vector> # include <algorithm> void deal(string &pos,int s,int e) { if(s>e) return; else { int c1=0,ts=s; vector<string> tmp; for(int i=s;i<=e;i++) { if(pos[i]=='1') c1--; else c1++; if(!c1) { deal(pos,ts+1,i-1); tmp.push_back(pos.substr(ts,i-ts+1)); ts=i+1; } } sort(tmp.begin(),tmp.end()); string ans=pos.substr(0,s); for(int i=0;i<tmp.size();i++) ans+=tmp[i]; ans+=pos.substr(e+1,pos.length()-e-1); pos=ans; } } int main() { // freopen("e.in","r",stdin); // freopen("ans.txt","w",stdout); int testcase; cin>>testcase; while(testcase--) { string a,b; cin>>a>>b; if(a.length()!=b.length()) { cout<<"different"<<endl; continue; } deal(a,0,a.length()-1); deal(b,0,b.length()-1); if(a==b) cout<<"same"<<endl; else cout<<"different"<<endl; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator