Saratov State University :: Online Contester


::Go
- home
- news
- register
- update personal info
- problemset archive
- submit
- status online
- standing
- contests
- virtual contests
- forum
- statistic
- FAQ
- links
- projects

::Poll
Are you registered on Codeforces?
Yes
No
What is it???

[results]

::webboard

I got WA on test 25
Author: jahanaraco
ID: 051549
Problem: 170
Contest: 0
Date: 2012-03-17 13:20:52

here is my code with a greedy algorithm :
can any one help me ,please?
_______________________________________________
#include <iostream>
#include <string>
using namespace std;
string a,b;
int ans;
void next(){
for(int i=0;i<b.size();i++){
if(b[i]==a[0]){
b=b.substr(0,i)+b.substr(i+1,b.size()-i-1);
ans+=i;
break;
}
}
a=a.substr(1,a.size()-1);
if(a.size())
next();
}
int main(){
cin>>a>>b;
int psia=0,psib=0;
if(a.size()==b.size())
for(int i=0;i<a.size();i++){
if(a[i]=='+')
psia++;
if(b[i]=='+')
psib++;
}
else{
ans=-1;
}
if(psia==psib)
next();
else
ans=-1;
cout<<ans<<endl;
return 0;
}


see sub-tree reply to that message


::Login
Forgot password?

::News
22.10.12 - The problems from the Southern Subregional Programming Contest 2012 added to the problemset archive (542 - 553).
22.10.12 - After the start of the contest the statements in PDF will be available by the link.
23.10.11 - The problems from the Southern Subregional Programming Contest 2011 added to the problemset archive (530 - 541).

::Counter

Server time: 2017-09-21 11:00:49Online Contester Team © 2002 - 2016. All rights reserved.