rohitm924's blog

By rohitm924, 12 years ago, In English

`#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); #ifndef ONLINE_JUDGE freopen("input","r",stdin); #endif int t,a,b,k,l,i,f,sum,p,q,z; char c[26]; char d; string s,w; cin>>t; while(t--) { cin>>s>>w>>a>>b>>k; for ( i = 'a' ; i <= 'z' ; i++ ) { c[i]=0; } for(i=0;i<w.length();i++) { d=w.at(i); c[d]++; } if(a==0 && b==0) { cout<<0<<"\n"; } else if(k==0) { cout<<-1<<"\n"; } else { sum=0; while(s.length()!=0 && w.length()!=0) { if(s[0]!=w[0]) { d=s[0]; f=c[d];//cout<<f<<"\n"; if(f>=1) { if(a<=k) { sum=sum+a; } else sum=sum+b; c[d]--; } else { sum=sum+b; } } s.erase(s.begin()); w.erase(w.begin()); //cout<<s<<" "<<w<<"\n"; } l=max(s.length(),w.length()); sum=sum+a*l; if(sum<=k) { cout<<sum<<"\n"; } else cout<<-1<<"\n"; } //} } }

Your text to link here...`

  • Vote: I like it
  • -23
  • Vote: I do not like it

»
12 years ago, hide # |
Rev. 2  
Vote: I like it +1 Vote: I do not like it
»
12 years ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

You at least understood your program?