11716 - Digital Fortress
Moderator: Board moderators
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11716 - Digital Fortress
Try using BufferedReader and BufferedWriter.
Check input and AC output for thousands of problems on uDebug!
Re: 11716 - Digital Fortress
Using BufferedReader/BufferedWriter made a difference. Thank you brianfry713
Re: 11716 - Digital Fortress
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;
}
}
}
![:(](./images/smilies/icon_frown.gif)
#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
_
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
Re: 11716 - Digital Fortress
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.
Don't forget to remove your code after getting accepted. ![8)](./images/smilies/icon_cool.gif)
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);
![8)](./images/smilies/icon_cool.gif)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
11716 - Digital Fortress
I keep getting WA.
REMOVED after AC
Issue: Comparing floating point numbers!
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.
Re: 11716 - Digital Fortress
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
Re: 11716 - Digital Fortress
Thanks lighted!
-
- New poster
- Posts: 1
- Joined: Tue Mar 31, 2015 12:45 am
Re: 11716 - Digital Fortress
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;
}