Page 3 of 3

### Re: 11360 - Have Fun with Matrices

Posted: Thu Mar 27, 2014 9:09 am
brianfry713,

Thanks for the great test case.

How did you generate these? Did you write a program to do this?

### Re: 11360 - Have Fun with Matrices

Posted: Thu Mar 27, 2014 9:14 am
plamplam wrote:You have to take the operations(for example inc, transpose, row a b etc) using scanf("%s");.When I tried with gets() the judge blessed me with a "Wrong Answer" All I did was use

Code: Select all

``getline(cin, aLine);``
where "aLine" is of type std::string and then check "aLine" - with the first character of the operation to be performed.

For the switch operations, I added the following lines

Code: Select all

``````istringstream ss(aLine);
ss >> aLine >> a >> b;``````
where "a" and "b" are of type integers.

In other words, there's nothing fancy going on with the judge's input.

If your code passes brianfry713's exhaustive test case, you should be good.

### Re: 11360 - Have Fun with Matrices

Posted: Thu Mar 27, 2014 9:23 pm
I often write a program using rand() to generate test cases.

### Re: 11360 - Have Fun with Matrices

Posted: Fri Mar 28, 2014 12:54 am
brianfry713 wrote:I often write a program using rand() to generate test cases.
Great stuff! Thanks for sharing.

### Re: 11360 - Have Fun with Matrices

Posted: Fri Aug 15, 2014 10:53 am
Getting TLE ! What should I do to get rid of it? Here is my code:

Code: Select all

``````#include<stdio.h>
struct matrix
{
int col;
int cl;
};
int main()
{
int t,n,c,comand,i,j,k,x,y,temp;
char oper;
struct matrix row;
struct matrix rw;
scanf("%d",&t);
for(c=1;c<=t;c++)
{
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
scanf("%d",&row[i].col[j]);
}
}
scanf("%d",&comand);
getchar();
while(comand--)
{
gets(oper);
if(oper=='i')
{
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
row[i].col[j]++;
}
}
}
else if(oper=='d')
{
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
row[i].col[j]--;
}
}
}
else if(oper=='r')
{
x=oper-'0';
y=oper-'0';
for(i=1;i<=n;i++)
{
temp=row[x].col[i];
row[x].col[i]=row[y].col[i];
row[y].col[i]=temp;
}
}
else if(oper=='c')
{
x=oper-'0';
y=oper-'0';
for(i=1;i<=n;i++)
{
temp=row[i].col[x];
row[i].col[x]=row[i].col[y];
row[i].col[y]=temp;
}
}
else if(oper=='t')
{
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
rw[i].cl[j]=row[i].col[j];
}
}
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
row[i].col[j]=rw[j].cl[i];
}
}
}
}
printf("Case %d#\n",c);
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(j!=1)
printf(" ");
printf("%d",row[i].col[j]);
}
printf("\n");
}
printf("\n");
}
return 0;
}
``````

### Re: 11360 - Have Fun with Matrices

Posted: Sat Aug 16, 2014 12:55 am
Try running your code on the sample input.

### Re: 11360 - Have Fun with Matrices

Posted: Sun Aug 24, 2014 7:16 pm

Code: Select all

``Accepted!!``

### Re: 11360 - Have Fun with Matrices

Posted: Thu Aug 28, 2014 12:33 am
Try input:

Code: Select all

``````1
1
9
11
inc
inc
inc
inc
inc
inc
inc
inc
inc
inc
inc
``````
Output should be 0

### Re: 11360 - Have Fun with Matrices

Posted: Thu Aug 28, 2014 5:10 am
brianfry713 wrote:Try input:

Code: Select all

``````1
1
9
11
inc
inc
inc
inc
inc
inc
inc
inc
inc
inc
inc
``````
Output should be 0
Thanks, Got AC!!   