### Saratov State University :: Online Contester

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

 ::Poll Are you registered on Codeforces?YesNoWhat 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;
}