Pagini recente » Cod sursa (job #984907) | Cod sursa (job #752340) | Cod sursa (job #1378259) | Cod sursa (job #2301846) | Cod sursa (job #397140)
Cod sursa(job #397140)
/*#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
FILE *f=fopen ("restante.in", "r");
FILE *g=fopen ("restante.out", "w");
int i,j,n,sw,k,n2;
char v[36001][20];
void shell (int n) {
int inj=n,i,sw;
char aux[20];
while (inj>1)
{
inj/=2;
do
{
sw=0;
for (i=0;i<=n-inj;i++)
if ( strcmp (v[i], v[i+inj])>0 )
{
strcpy (aux, v[i]);
strcpy (v[i], v[i+inj]);
strcpy (v[i+inj], aux);
sw=1;
}
}
while (sw);
}
}
int main() {
fscanf (f, "%d", &n);
for (i=0;i<=n-1;i++)
{
fscanf (f, "%s", &v[i]);
sort (v[i], v[i]+strlen(v[i]));
}
shell (n-1);
for (i=0;i<=n-1;i++)
{
sw=0; j=i+1;
while ( strcmp (v[i], v[j])==0 )
{ j++; sw=1; }
if (sw)
i=j-1;
else
k++;
}
fprintf (g, "%d", k);
return 0;
}
#include <iostream.h>
#include <stdio.h>
#include <vector>
#include <string.h>
#include <algorithm>
using namespace std;
FILE *f=fopen ("restante.in", "r");
int main()
{
int n;
char oneword[20];
vector<string> words;
fscanf (f, "%d", &n);
for (int i=0; i < n; i++)
{
// cout << "Enter word " << i+1 << " of " << n << "\n";
fscanf (f, "%s", &oneword);
sort (oneword, oneword+strlen(oneword));
words.push_back(oneword);
}
cout << "\n\nUnsorted: \n\n";
for (int j= 0; j < n; j++)
cout << words[j] << "\n";
sort (words.begin(),words.end());
cout << "\n\nSorted: \n\n";
for (int k= 0; k < n; k++)
cout << words[k] << "\n";
return 0;
}
*/
#include <stdio.h>
#include <string.h>
#include <vector.h>
#include <algorithm>
using namespace std;
FILE *f=fopen ("restante.in", "r");
FILE *g=fopen ("restante.out", "w");
int i,n,sw,j,k;
char v[20];
vector<string> chitanta;
int main() {
fscanf (f, "%d", &n);
for (i=0;i<=n-1;i++) // citirea cuvintelor + sortarea lor
{
fscanf (f, "%s", &v);
sort (v, v+strlen(v));
chitanta.push_back(v);
}
sort (chitanta.begin(), chitanta.end());
for (i=0;i<=n-1;i++)
{
sw=0; j=i+1;
while (j<n && chitanta[i]==chitanta[j])
{ j++; sw=1; }
if (sw)
i=j-1;
else
k++;
}
fprintf (g, "%d", k);
return 0;
}