- Code: Select all
sdfretf
gggfrtttereee
dfffrrrdfdf
zzffffferrrre
aaseajwelrkjlsdj
ewrwerjwelrjwe
#
output:
- Code: Select all
1826
1801379
1130
535920
1468380809
3265624
Moderator: Board moderators
sdfretf
gggfrtttereee
dfffrrrdfdf
zzffffferrrre
aaseajwelrkjlsdj
ewrwerjwelrjwe
# 1826
1801379
1130
535920
1468380809
3265624
using namespace std;
#include <iostream>
#include <stdlib.h>
#include <string>
#include <new>
#include <algorithm>
#include <iomanip>
/*
currently suffering the dreaded wrong output
-I know it works for arrays of length 1-5 (regardless of character values)
-I have looked on the help board and tried other peoples input and I have gotten identical output
-I am assuming either I am messing up the output or messing up some fringe cases
*/
int permutations(string);
//finds the permutations of a sorted string (does not double count)
int permutations(string list)
{
int length=list.length();
long int sum =1;
if (length==0)
return(0);
if (length == 1)
return(sum);
for(int counter=2; counter<=length;counter++)
{
sum=sum*counter;
}
int count=1;
for(int j=1;j<length;j++)
{
if(list[j-1]==list[j])
{
count++;
sum=sum/count;
}
else
count=1;
}
return(sum);
}
//runs the program
int main()
{
string tested;
cin>>tested;
string test="#";
while( tested!=test)
{
int length=tested.length();
string sorted =tested;
sort(sorted.begin(), sorted.end());
long int sum=1;
for(length;length>1;length--)
{
int i=0;
while(sorted[i]!=tested[0]) //test for first letter and find its place
{
string temp=sorted;
temp.erase(i,1);
sum+=permutations(temp);
while(sorted[i]==sorted[i+1])
{
i++;
}
i++;
}
tested.erase(0,1);
sorted.erase(i,1);
}
std::cout << std::right << std::setw(11) << sum << std::endl;
cin>>tested;
}
}
Users browsing this forum: No registered users and 1 guest