I have this problem to solve for preparing for the olympiad and i'm not quite fond of the functions so that i want to do it classically but i find it harder.Here it goes:
"During a desert operation a group of soldiers were lost from different squads.After the storm passed the soldiers need to regroup to their squads, so they have some metallic tags on which their identification number is written on.So, the soldiers of the same squad have the ident. number formed by the same digits but arranged in a different way. For example, ident numbers 78003433, 83043073,33347008 tells us that the three soldiers are from the same squad.
REQUEST:
Having given the n numbers from the ident tags, you have to regroup the soldiers into squads indicating the number of squads found(a squad must be formed by minimum 1 soldier), the number of soldiers from the most numerous squad, the number of squads that have this number and also the components of this kind of squad(with the max number of regrouped soldiers).
ENTRY INFO:
The file of input "plutoni" will contain on the first line the number of the n soldiers found, and on each of the next n lines a number of identification of the n soldiers.
OUTPUT info:
The file of output "plutono" will contain on the first line the number of squads that are reassembled. On the second line it will contain the number of soldiers from the most numerous squad that is reassembled.On the third line it will contain the number of squads that have the maximum number of reunited soldiers.On the fourth line the formation of this kind of squad will be shown, the soldiers identification number being written each after another separated by a space(_).
EXAMPLE:if the input file contains the following:
10
1223
123
666
321
7890
2213
312
655
1000
1322
the output file will look like this:
6
3
2
321 312 123.
That's quite it..so here's what i've produced so far:
#include <iostream>
#include <fstream.h>
using namespace std;
int nr[200000];
int nrsort[200000];
long nrp,n,maxim,nrmax;
long sortare(long x) {//means sorting
long aux,c,y;
aux=x;
y=0;
for(c=9;c>=0;c--) {
while(x) {
if(x%10==c) {
y=y*10+x%10;}
x=x/10;}
x=aux;}
return y;}
void main() {
long i,j,p,pmax;
long aux;
fstream f1("plutoni.txt", ios::in);
f1>>n;
for(i=1;i<=n;i++) {
f1>>nr[i];
nrsort[i]=sortare(nr[i]);
f1.close();}
i=1;
nrp=nrmax=maxim=0;
while(i<=n) {
p=i;
j=i+1;
while(j<=n){
if(nrsort[i]==nrsort[j]) {
i++;
aux=nr[i];
nr[i]=nr[j];
nr[j]=aux;
aux=nrsort[i];
nrsort[i]=nrsort[j];
nrsort[j]=aux;}
j++;}
i++;
nrp++;
if(i-p>maxim) {
maxim=i-p;
nrmax=1;
pmax=p;}
else if(i-p==maxim) {
nrmax++;}}
fstream f2("plutono.txt", ios::out);
f2<<nrp<<endl<<maxim<<endl<<nrmax<<endl;
for(i=pmax;i<pmax+maxim;i++) {
f2<<nr[i]<<" ";
f2.close();}
}