11716 - Digital Fortress

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

Moderator: Board moderators

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

Re: 11716 - Digital Fortress

Post by brianfry713 » Tue Oct 08, 2013 10:05 pm

Try using BufferedReader and BufferedWriter.
Check input and AC output for thousands of problems on uDebug!

alexiago
New poster
Posts: 14
Joined: Thu Jan 24, 2008 6:34 pm

Re: 11716 - Digital Fortress

Post by alexiago » Tue Oct 08, 2013 10:45 pm

Using BufferedReader/BufferedWriter made a difference. Thank you brianfry713

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 11716 - Digital Fortress

Post by uDebug » Mon Mar 17, 2014 12:15 pm

brianfry713, neilor,

Thanks for the test cases.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

rasha7695
New poster
Posts: 1
Joined: Mon Oct 06, 2014 4:43 am

Re: 11716 - Digital Fortress

Post by rasha7695 » Mon Oct 06, 2014 4:47 am

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;
}
}
}

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

Re: 11716 - Digital Fortress

Post by lighted » Mon Oct 06, 2014 2:14 pm

_
Last edited by lighted on Mon Oct 06, 2014 2:23 pm, edited 2 times in total.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

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

Re: 11716 - Digital Fortress

Post by lighted » Mon Oct 06, 2014 2:22 pm

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)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

mjimaz
New poster
Posts: 6
Joined: Thu Jan 09, 2014 1:03 am

11716 - Digital Fortress

Post by mjimaz » Sat Dec 06, 2014 10:27 pm

I keep getting WA.

REMOVED after AC

Issue: Comparing floating point numbers!
Last edited by mjimaz on Sun Dec 07, 2014 4:41 pm, edited 1 time in total.

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

Re: 11716 - Digital Fortress

Post by lighted » Sun Dec 07, 2014 3:13 pm

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);
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

mjimaz
New poster
Posts: 6
Joined: Thu Jan 09, 2014 1:03 am

Re: 11716 - Digital Fortress

Post by mjimaz » Sun Dec 07, 2014 4:39 pm

Thanks lighted!

ashikulhaque
New poster
Posts: 1
Joined: Tue Mar 31, 2015 12:45 am

Re: 11716 - Digital Fortress

Post by ashikulhaque » Tue Mar 31, 2015 12:54 am

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.

Post Reply

Return to “Volume 117 (11700-11799)”