Code: Select all
Removed
After A/C
Moderator: Board moderators
Code: Select all
Removed
After A/C
Code: Select all
code removed
Code: Select all
--- code removed
if(sqrt(strLength)*sqrt(strLength) == strLength) {
--- code removed
Code: Select all
#include<iostream.h>
#include<math.h>
#include<string.h>
#include<stdio.h>
int main()
{
char a[11050];
int i,n,j,Case,k,p;
cin>>Case;
for(k=0;k<Case;k++)
{
scanf("%[^\n]",a);i=getchar();
n=strlen(a);
p=sqrt(n);
if(p*p==n)
{
for(j=0;j<p;j++)
{
i=j;
for(;i<n;i=i+p)
cout<<a[i];
}
// cout<<endl;
}
else
cout<<"INVALID";//<<endl;
if(Case!=k)
cout<<endl;
}
return 0;
}
Code: Select all
removed after AC
Code: Select all
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
void main()
{
int t,i,j;
long int length,k;
double root;
char arr[10001],**p;
scanf("%d",&t);
fflush(stdin);
while(t--)
{
gets(arr);
length=strlen(arr);
root=sqrt(length);
if(floor(root)==ceil(root))
{
k=(int) root;
p=(char **) malloc(k*sizeof(char *));
for(i=0;i<root;i++) p[i]=(char *) malloc(k*sizeof(char));
k=0;
for(i=0;i<root;i++)
{
for(j=0;j<root;j++)
{
p[i][j]=arr[k];
k++;
}
}
for(i=0;i<root;i++)
{
for(j=0;j<root;j++)
{
putchar(p[j][i]);
}
}
putchar('\n');
}
else printf("INVALID\n");
}
}
if I am not wrong, i think your are checking if the length is a perfect square. its better if you do it like thislength=strlen(arr);
root=sqrt(length);
if(floor(root)==ceil(root))
Code: Select all
if(root*root==length)
Code: Select all
Removed after AC
Thank You!brianfry713 wrote:You're assuming there are only up to 1000 characters per line when the problem statement says up to 10000.
Code: Select all
#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;
int main(){
int n;
cin>>n;
getchar();
for(int i=1; i<=n; i++){
char ciph[10010], deciph[10010];
int len, sq;
gets(ciph);
len = strlen(ciph);
sq = sqrt( (float)len );
if( sq*sq != len ) cout<<"INVALID"<<endl;
else{
int dex=0;
for(int j=0; j<sq; j++ )
for(int k=0; k<sq; k++, dex++)
deciph[dex] = ciph[ sq*k + j ];
deciph[dex]=NULL;
cout<<deciph<<endl;
}
}
return 0;
}