Can someone please check this code for me? Judges' feedback for this code is wrong answer. I modified it several times to get it working like this thread's outputs (not counting duplicate strings) and an acc code's outputs (takes only alphanumeric characters and digits). But in vain.
Code: Select all
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
using namespace std;
char name[105][1005],line[105][1005],temp[1005];
int i,j,k,n,test,z,length[105],t,p;
void init ()
{
for (i=0;i<105;i++)
{
for (j=0;j<305;j++)
{
name[i][j]='\0';
line[i][j]='\0';
}
}
for (i=0;i<305;i++)
temp[i]='\0';
}
int main ()
{
:roll: scanf ("%d",&test);
getchar ();
for (z=1;z<=test;z++)
{
init ();
n=0;
while(1)
{
if(!gets(temp))
break;
k=strlen (temp);
if(k==0)
{
break;
}
length[n]=k;
strcpy(name[n],temp);
n++;
}
/* Sorts the input lexicographically*/
for (i=0;i<n;i++)
{
for (j=i+1;j<n;j++)
{
if (strcmp(name[i],name[j])>0)
{
strcpy(temp,name[i]);
strcpy (name[i],name[j]);
strcpy (name[j],temp);
t=length[i];
length[i]=length[j];
length[j]=t;
}
else if (strcmp(name[i],name[j])==0) /* if two inputs are same one is nullified*/
{
strcpy (name[j],"\0");
}
}
}
/************************/
/*deletes the unnecessary characters and spaces and saves it to a new array*/
for (i=0;i<n;i++)
{
k=0;
for (j=0;j<length[i];j++)
{
if (isalpha(name[i][j]) || isdigit (name[i][j]))
//if (!isspace(name[i][j]))
{
line[i][k++]=name[i][j];
}
}
length[i]=k;
strcpy (temp,line[i]);
sort (temp,temp+k);
strcpy (line[i],temp);
}
/********************************/
/*Output portion*/
for (i=0;i<n;i++)
{
for (j=i+1;j<n;j++)
{
{
if (strcmp(line[i],line[j])==0)
{
{
if (strcmp(name[i],name[j])!=0)
{
printf ("%s = %s\n",name[i],name[j]);
}
}
}
}
}
}
/****************************/
/*prints blank line between cases. But normally multiple input programs*/
/*don't follow this, i know. I got it from an accepted code*/
if (z<test)
printf ("\n");
}
return 0;
}
The inputs and outputs all over the board are somewhat confusing.
Code: Select all
erosh
erosh /*same as first one*/
horse
horse /*it's already above it*/
ac bd
a cbd
q
q /*same as one above it*/
[horse]'
[e]rosh'
iiiiiiiiiiiiij
iiiiiiiiiiiiji
orchestra
pq
qp
carthorse
erosh /*same as first one*/
horsecart
ok i now donut
oknow uidot n
i do not know u
abdc
kencti kecut
kecut kencit
So what is the actual output?
this one
Code: Select all
[e]rosh' = [horse]'
a cbd = abdc
a cbd = ac bd
abdc = ac bd
carthorse = horsecart
carthorse = orchestra
erosh = erosh
erosh = erosh
erosh = horse
erosh = horse
erosh = erosh
erosh = horse
erosh = horse
erosh = horse
erosh = horse
horse = horse
horsecart = orchestra
i do not know u = ok i now donut
i do not know u = oknow uidot n
iiiiiiiiiiiiij = iiiiiiiiiiiiji
kecut kencit = kencti kecut
ok i now donut = oknow uidot n
pq = qp
q = q
or this one
Code: Select all
[e]rosh' = [horse]'
a cbd = abdc
a cbd = ac bd
abdc = ac bd
carthorse = horsecart
carthorse = orchestra
erosh = horse
horsecart = orchestra
i do not know u = ok i now donut
i do not know u = oknow uidot n
iiiiiiiiiiiiij = iiiiiiiiiiiiji
kecut kencit = kencti kecut
ok i now donut = oknow uidot n
pq = qp
or this?
Code: Select all
[e]rosh' = [horse]'
[e]rosh' = erosh
[e]rosh' = horse
[horse]' = erosh
[horse]' = horse
a cbd = abdc
a cbd = ac bd
abdc = ac bd
carthorse = horsecart
carthorse = orchestra
erosh = horse
horsecart = orchestra
i do not know u = ok i now donut
i do not know u = oknow uidot n
iiiiiiiiiiiiij = iiiiiiiiiiiiji
kecut kencit = kencti kecut
ok i now donut = oknow uidot n
pq = qp
First output contradicts mf's output strategy as far as i understood. But again this is an acc code's output in another thread. So I hope some one can give me a hand and tell me what's wrong with my code and which one is correct output.
Best regards.