Page 3 of 3

Re: 11716 - Digital Fortress

Posted: Tue Oct 08, 2013 10:05 pm
by brianfry713
Try using BufferedReader and BufferedWriter.

Re: 11716 - Digital Fortress

Posted: Tue Oct 08, 2013 10:45 pm
by alexiago
Using BufferedReader/BufferedWriter made a difference. Thank you brianfry713

Re: 11716 - Digital Fortress

Posted: Mon Mar 17, 2014 12:15 pm
by uDebug
brianfry713, neilor,

Thanks for the test cases.

Re: 11716 - Digital Fortress

Posted: Mon Oct 06, 2014 4:47 am
by rasha7695
why WA?? :(
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main(){
int t;
cin>>t;
string s;
for(int p=0;p<=t;p++){
getline(cin,s);
double b=sqrt(s.length());
int c=floor(b);
char a[c][c];
if(b-floor(b)!=0)
cout<<"INVALID"<<endl;
else
{
int k=0;
for(int i=0;i<b;i++){
for(int j=0;j<b;j++){
a[j]=s[k];
k++;
}
}
for(int i=0;i<b;i++){
for(int j=0;j<b;j++){
cout<<a[j];
}
}
cout<<endl;
}
}
}

Re: 11716 - Digital Fortress

Posted: Mon Oct 06, 2014 2:14 pm
by lighted
_

Re: 11716 - Digital Fortress

Posted: Mon Oct 06, 2014 2:22 pm
by lighted
Use code tags. After reading first number, you must read newline char at that line. If you don't, first getline command will read empty string. Your for operator must run only t times.

Add one getline to read newline char and make for loop run only t times.

Code: Select all

cin >> t;

string s;

getline(cin,s);

for (int p = 0; p < t; p++) {
   getline(cin,s);
Don't forget to remove your code after getting accepted. 8)

11716 - Digital Fortress

Posted: Sat Dec 06, 2014 10:27 pm
by mjimaz
I keep getting WA.

REMOVED after AC

Issue: Comparing floating point numbers!

Re: 11716 - Digital Fortress

Posted: Sun Dec 07, 2014 3:13 pm
by lighted
Always try to avoid floating point. It is not correct to compare doubles. Change code to

Code: Select all

int i, j, x, sq;
double length;
..
length = strlen(word);
sq = sqrt(length);

Re: 11716 - Digital Fortress

Posted: Sun Dec 07, 2014 4:39 pm
by mjimaz
Thanks lighted!

Re: 11716 - Digital Fortress

Posted: Tue Mar 31, 2015 12:54 am
by ashikulhaque

Code: Select all

#include<stdio.h>
#include<string.h>
#include<math.h>

int main()
{
    char str[1000000];
    int i,t,l,j,c,k,sq;
    float s;
    scanf("%d",&t);
    scanf("\r");
    for(i=1;i<=t;i++){
        if(i!=1)
            printf("\n");
        gets(str);
        l=strlen(str);
        s=sqrt(l);
        sq=sqrt(l);
        if(s!=sq)
            printf("INVALID");
        else{
            char ans[l];
            c=0;
            k=0;
            while(c<s){
                for(j=c;j<l;k++){
                    printf("%c",str[j]);
                    j+=s;
                }
                c+=1;
            }
        }
    }
    return 0;
}

getting WA but can't find the problem.All test cases also works.