11221 - Magic square palindromes.

All about problems in Volume 112. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh
Contact:

Re: 11221 - Magic square palindromes

Post by Shahidul.CSE » Sat Aug 09, 2014 6:14 am

Thanks lbv! Now Got AC. :D :D
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com

gfv
New poster
Posts: 6
Joined: Wed Jun 26, 2013 3:23 am

Re: 11221 - Magic square palindromes.

Post by gfv » Tue Nov 18, 2014 5:06 pm

It gives me WA even though I passed all test cases:

Code: Select all

Removed due to AC
EDIT: Nvm, i was forgeting the almost invisible ":" at the end of the "Case n#:" line
Last edited by gfv on Wed Nov 19, 2014 2:49 am, edited 3 times in total.

gfv
New poster
Posts: 6
Joined: Wed Jun 26, 2013 3:23 am

Re: 11221 - Magic square palindromes

Post by gfv » Tue Nov 18, 2014 6:01 pm

gdisastery wrote:Input:

Code: Select all

2
:) ~ :D ~~~~ :))))))) :D :D :D
:P :P :P :P
AC Output:

Code: Select all

Case #1:
2
Case #2:
2
I ran it on toolkit and it gave me the same output my code did:

Code: Select all

Case #1:
0
Case #2:
0
Indeed, it doesn't really matter once judge ignores capital letters (there won't be capital inputs, it's in the specification).

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11221 - Magic square palindromes.

Post by brianfry713 » Tue Nov 18, 2014 11:18 pm

Always print a newline char at the end of the last line.
Check input and AC output for thousands of problems on uDebug!

gfv
New poster
Posts: 6
Joined: Wed Jun 26, 2013 3:23 am

Re: 11221 - Magic square palindromes.

Post by gfv » Wed Nov 19, 2014 1:04 am

Did it, still WA. Already tried with and without the final \n;

Shafayat
New poster
Posts: 7
Joined: Mon Jan 19, 2015 11:32 am

Re: 11221 - Magic square palindromes.

Post by Shafayat » Tue Feb 03, 2015 4:32 pm

Can anyone tell me why I got WA?

Code: Select all

Removed after accepted
Last edited by Shafayat on Thu Feb 05, 2015 9:23 pm, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11221 - Magic square palindromes.

Post by brianfry713 » Thu Feb 05, 2015 1:27 am

Describe or comment your code. What are o, q, and r?
Check input and AC output for thousands of problems on uDebug!

Shafayat
New poster
Posts: 7
Joined: Mon Jan 19, 2015 11:32 am

Re: 11221 - Magic square palindromes.

Post by Shafayat » Thu Feb 05, 2015 7:36 pm

As gets() function can not get input after using scanf("%d"...., so I input number of test case in a string p[10]. Then convert in into integer. After that I use gets(m) to input characters of the square. From m, I separate all alphabets into n. Then check whether its length is a square of a integer number or not. If it is not, then display "No magic". Else, I copy alphabets of the square vertically in string o. It means starts from (1,1) go down till end of the column.Then starts from next column and so on. After that reverse the string n to the string q. r is used here to store again vertical alphabets, means starts from the ending square and go up till starting square of the column. Then go to the ending of previous square and again go up and so on. Then compare n,o,q and r. If these are same display square. Else display No magic.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11221 - Magic square palindromes.

Post by brianfry713 » Thu Feb 05, 2015 9:18 pm

The length of a line can be up to 10,000 chars long.
Increase the size of m, n, o, q, and r to at least 10,001.
Check input and AC output for thousands of problems on uDebug!

Shafayat
New poster
Posts: 7
Joined: Mon Jan 19, 2015 11:32 am

Re: 11221 - Magic square palindromes.

Post by Shafayat » Thu Feb 05, 2015 9:22 pm

Thanks a lot. Got accepted

coder.tanvir
New poster
Posts: 11
Joined: Mon Mar 09, 2015 10:30 am

Re: 11221 - Magic square palindromes.

Post by coder.tanvir » Tue May 12, 2015 10:43 pm

Code: Select all

#include <bits/stdc++.h>
int main()
{
    char cas[10];
    int ca , x=0;
    gets(cas);
    ca=atoi(cas);
    while(ca--)
    {
        char line[10010];
        char final_[10010];
        char final_1[10010];
        char final_2[10010];
        char final_3[10010];
        gets(line);
        int len = strlen(line) ;
        int j=0;
        
        for(int i=0; i< len; i++)
            if(line[i]>='a' && line[i]<='z')
                final_[j++]=line[i];
                
        final_[j]='\0';

        int sp=sqrt(j);
        if(sp*sp!=j) printf("Case #%d:\nNo magic :(\n",++x);
        else{
            int pos=0;
            
            for(int i=0 ; i< sp ; i++)
                for(int j=0 ; j<sp ; j++)
                    final_1[pos++]=final_[j*sp+i];

            final_1[pos]='\0';
            pos=0;

            for(int i=sp-1 ; i>=0 ; i--)
                for(int j=sp-1 ; j>=0 ; j--)
                    final_2[pos++]=final_[j*sp+i];

            final_2[pos]='\0';
            pos=0;

            for(int i=sp-1 ; i>=0 ; i--)
                for(int j=sp-1 ; j>=0 ; j--)
                    final_3[pos++]=final_[i*sp+j];

            final_3[pos]='\0';
            if(strcmp(final_,final_1)==0 && strcmp(final_,final_2)==0 && strcmp(final_,final_3)==0 ) printf("Case #%d\n%d\n",++x,sp);
            else printf("Case #%d:\nNo magic :(\n",++x);
        }
    }
    return 0;
}

getting WA

KiBurst
New poster
Posts: 2
Joined: Sat Oct 03, 2015 1:52 pm

Re: 11221 - Magic square palindromes.

Post by KiBurst » Sat Oct 03, 2015 1:57 pm

It was already said once before but I am going to restate it as it caused me over an hour of grief.
length(L) < 10.000 is incorrect, it is actually length(L) <= 10.000
My approach involved initially checking if the input String was an appropriate size in order to fit into a square and ruling out the possibility of a 100x100 square was giving me WA.

kaiser harlequin
New poster
Posts: 2
Joined: Sat Jan 21, 2017 10:07 am

Re: 11221 - Magic square palindromes.

Post by kaiser harlequin » Sat Jan 21, 2017 10:44 am

Code: Select all

#include <iostream>
#include<math.h>
#include<stdio.h>
using namespace std;

int main() {

string w;

int quit[999],lo,al[999];
//getline(cin,w);
cin>>lo;

cin.ignore(256, '\n');


for(int y=0;y<lo;y++)
{

int u=0,x=0,qw;
float r;
char f[1000][1000];
string str,we="";
getline(cin, str);

//cout<<str;
for(long long int i=0;i<str.length();i++)
{
int b=str[i];

if(b>=97 && b<=122)
we=we+str[i];

}
//cout<<we<<endl;
r=sqrt(we.length());
qw=(int)r;
//cout<<qw;
if(qw==r)
{
for(long long int ty=0;ty<qw;ty++)
{
for(long long int qe=0;qe<qw;qe++)
{
f[ty][qe]=we[x];
++x;
}
}
for(long long int hy=0;hy<qw;hy++)
{
for(long long int rq=0;rq<qw;rq++)
{

//cout<<f[hy][rq];
if(f[hy][rq]!=f[rq][hy])
++u;
}
//cout<<endl;
}

}
else u=1;
//cout<<u;

quit[y]=u;
al[y]=qw;
}
for(int p=0;p<lo;p++)
{
if(quit[p]==0)
{


cout<<"Case #"<<p+1<<":"<<endl;
if(p!=(lo-1))
cout<<al[p]<<endl;
else cout<<al[p];

}


else
{cout<<"Case #"<<p+1<<":"<<endl<<"No magic :(";
if(p!=(lo-1))
cout<<endl;

}
}




}






[quote]why wrong answer despite sattisfying most test cases.[/quote]

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 11221 - Magic square palindromes.

Post by lighted » Sun Mar 12, 2017 2:57 pm

Don't double post. Input

Code: Select all

1
sator azepo tenet opera rotas
Output

Code: Select all

Case #1:
No magic :(
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

Post Reply

Return to “Volume 112 (11200-11299)”

Who is online

Users browsing this forum: No registered users and 1 guest