....:(
Posted: Fri Sep 21, 2007 6:37 pm
jan vai at first i actually misunderstood the problem. now i edited my code and consider your input-output. it gives me right, bt i am still getting WA!!!!!where is the bug?
Code: Select all
Code Removed After AC
Code: Select all
if (flag)
{
check="";
for (int s=input.size()-1;s>=input.size()-root;s--)
for (int t=s;t>=0;t-=root)
check+=input[t];
if (input!=check)
flag=false;
}
Code: Select all
for (int s=input.size()-1;s>=input.size()-root;s--)
for (int t=s;t>=0;t-=root)
#include <stdio.h>
#include <string.h>
#include <math.h>
char in[10000];
char help[10000];
char check[10000][10000];
int main()
{
int ts;
scanf("%d",&ts);
int cs=0;
while(ts)
{
cs++;
int flag=1;
ts--;
fflush(stdin);
gets(in);
int lenin=strlen(in);
int lenhelp=0;
for(int i=0;i<lenin;i++)
{
if(in>='a' && in<='z')
help[lenhelp++]=in;
}
// printf("%d\n",lenhelp);
double ck=sqrt(lenhelp);
int chk=ck;
if(ck-chk>0)
flag=0;
if(flag)
for(int i=0,k=0;i<chk;i++)
{
for(int j=0;j<chk;j++)
{
check[j]=help[k++];
}
}
if(flag)
for(int i=0,k=0;i<chk;i++)
for(int j=0;j<chk;j++)
if(check[j]!=help[k++])
{
flag=0;
break;
}
if(flag)
for(int i=chk-1,k=0;i>=0;i--)
for(int j=chk-1;j>=0;j--)
if(check[j]!=help[k++])
{
flag=0;
break;
}
if(flag)
for(int i=chk-1,k=0;i>=0;i--)
for(int j=chk-1;j>=0;j--)
if(check[j]!=help[k++])
{
flag=0;
break;
}
if(flag)
printf("Case #%d:\n%d\n",cs,chk);
else
printf("Case #%d:\nNo magic\n",cs);
}
return 0;
}
Code: Select all
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#define TAM 10002
char word[TAM], str[TAM], A[TAM], B[TAM], C[TAM], D[TAM];
char square[TAM][TAM];
bool palindromo(int len){
for(int i = 0, j = len-1 ; i < len && j>=0 ; ++i, j--){
if( A[i]!=A[j] || B[i]!=B[j] || C[i]!=C[j] || D[i]!=D[j]
|| A[i]!=B[i] || A[i]!=C[i] || A[i]!=D[i])
return false;
}
return true;
}
int main(){
int i, ii, t, k, len_str;
bool flag ;
scanf("%d", &t);
for(int tt = 1; tt <= t; tt++){
fflush(stdin);
gets(word);
i = 0, len_str = 0;
for(; i < strlen(word); ++i){
if(word[i] >= 'a' && word[i] <= 'z'){
str[len_str] = word[i];
len_str++;
}
}
printf("Case #%d:\n", tt);
flag = true;
k = (int)sqrt((double)len_str);
if( k*k != len_str ){
printf("No magic :(\n");
}
else{
for(int i = 0 ; i < len_str; ++i){
square[i/k][i%k] = str[i];
}
int pos = 0;
for(int i = 0; i < k; ++i){
for(int j = 0; j < k ; ++j){
A[pos] = square[i][j];
pos++;
}
}
pos = 0;
for(int i = 0; i < k; ++i){
for(int j = 0; j < k ; ++j){
B[pos] = square[j][i];
pos++;
}
}
pos = 0;
for(int i = k-1; i >= 0; --i){
for(int j = k-1; j >= 0 ; --j){
C[pos] = square[i][j];
pos++;
}
}
pos = 0;
for(int i = k-1; i >= 0; --i){
for(int j = k-1; j >= 0 ; --j){
D[pos] = square[j][i];
pos++;
}
}
palindromo(len_str) == true ? printf("%d\n", k) : printf("No magic :(\n");
}
}
return 0;
}