256 - Quirksome Squares

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

Moderator: Board moderators

Minilek
Learning poster
Posts: 90
Joined: Tue Jul 27, 2004 9:34 am
Location: Cambridge, MA
Contact:

Post by Minilek »

Is there a way to get printf formatting to have some of the things as variables? Hm..that last sentence was very vague, but this is what I mean. Say I want the following:

[c]
if (digits==2) printf("%02ld\n",something);
else if (digits==4) printf("%04ld\n",something);
[/c]

etc.

Is there some way to get rid of the need for if's by using
some kind of variable in the printf formatting?

Thanks.

P.S. Julien: Do you know problem 106 that involves finding pythagorean triples? I am not sure but I think using that method to generate triples, you can do this problem fast without precalculating (but just leave it as z^2 instead of reducing it back to z).

little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Post by little joey »

Hmm, no direct way, AFAIK, but this little program shows a way to do it:

[c]#include <stdio.h>

int main(){
char formatstring[32];
int digits,i;

i=1234;

digits=10;
sprintf(formatstring,"%%0%dld\n",digits);
printf(formatstring,i);

digits=8;
sprintf(formatstring,"%%0%dld\n",digits);
printf(formatstring,i);

return 0;
}
[/c]

dmc
New poster
Posts: 5
Joined: Mon Dec 19, 2005 7:05 pm

256 - Quirksome Squares

Post by dmc »

problem solved

Dickon
New poster
Posts: 4
Joined: Thu Jun 15, 2006 4:10 am

256~Output Limit Exceeded(help><")

Post by Dickon »

#include<stdio.h>

int main()
{

int c;

while(scanf("%d",&c)!=0){

if(c==2){

printf("%s\n%s\n%s\n","00","01","81");
}

else if(c==4){

printf("%s\n%s\n%s\n%s\n%s\n","0000","0001","2025","3025","9801");

}



else if(c==6){

printf("%s\n%s\n%s\n%s\n%s\n","000000","000001","088208","494209","998001");


}

else if(c==8){

printf("%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n","00000000","00000001",
"04941729","07441984","24502500","25502500","52881984","60481729","99980001");



}


}

return 0;
}



it is my code for 256.

but they send me email:
Your program output is greater (4236247 bytes) than the maximum
allowed for any problem by this judge (4194304 bytes).
You must interprete this as a Wrong Answer (in fact, is wrong!).
By some reason your program is writing an unlimited output.

how should i do,someone could tell me,please?

the LA-Z-BOy
Learning poster
Posts: 94
Joined: Wed Jul 31, 2002 12:44 pm
Location: Dacca, Bangladesh
Contact:

Post by the LA-Z-BOy »

You are getting Output Limit Exceeded because your program doesn't break the loop. Your condition is

Code: Select all

 while(scanf("%d",&c)!=0){ 
scanf returns EOF(equivalent to -1) on end-of-file / error, not ZERO.
so it could be written as

Code: Select all

 while(scanf("%d",&c)!=-1){ 
or

Code: Select all

 while(scanf("%d",&c)!=EOF){ 
or

Code: Select all

 while(scanf("%d",&c)==1){ 
Istiaque Ahmed [the LA-Z-BOy]

Donotalo
Learning poster
Posts: 56
Joined: Sat Aug 20, 2005 11:05 am
Location: Bangladesh

256 WA

Post by Donotalo »

input: 2 -> 3 values in output
input: 4 -> 5 values in output
input: 6 -> 4 values in output
input: 8 -> 7 values in output

is it ok? why i'm getting WA? i'm padding with 0's as stated in the program. please help!
Image

daveon
Experienced poster
Posts: 229
Joined: Tue Aug 31, 2004 2:41 am
Location: TORONTO, CANADA

Post by daveon »

Hi,

input: 6 -> 5 values in output
input: 8 -> 9 values in output

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 256..............another piece of cake?

Post by Obaida »

Some one Please check my input & output... What's wrong I am getting WA>..
Input

Code: Select all

Input:
2
4
6
8
Output:
00
01
81
0000
0001
2025
3025
9801
000000
000001
088209
494209
998001
00000000
00000001
04941729
07441984
24502500
25502500
52881984
60481729
99980001
try_try_try_try_&&&_try@try.com
This may be the address of success.

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 256..............another piece of cake?

Post by Obaida »

Ok... I got Acc.. That was a bad mistake... :evil:
try_try_try_try_&&&_try@try.com
This may be the address of success.

peluso
New poster
Posts: 1
Joined: Mon Sep 22, 2008 5:07 am

Re: 256..............another piece of cake?

Post by peluso »

I too do not know why I'm getting WA. Can anyone see what's wrong? Thanks!
input:
2
4
6
8
output:
00
01
81
0000
0001
2025
3025
9801
000000
000001
088209
494209
998001
00000000
00000001
04941729
07441984
24502500
25502500
52881984
60481729
99980001

sauronnikko
New poster
Posts: 2
Joined: Thu Dec 25, 2008 12:35 am

256 - Runtime Error

Post by sauronnikko »

Hi. I've been getting Runtime Error with this code. I have tested it quite a few times and I still don't know what's happening

Code: Select all

import java.util.*;

public class Main {
    public static void main (String args[]) {
        Scanner input = new Scanner (System.in);
        while (true)    {
            int digits = input.nextInt();
            if (digits != 2 && digits != 4 && digits != 6 && digits != 8)
                break;
            else    {
                if (digits == 2)    {
                    System.out.println ("00\n01\n81");
                }
                else if (digits == 4)   {
                    System.out.println ("0000\n0001\n2025\n3025\n9801");
                }
                else if (digits == 6)   {
                    System.out.println ("000000\n000001\n088209\n494209\n998001");
                }
                else if (digits == 8)   {
                    System.out.println ("00000000\n00000001\n04941729\n07441984\n24502500\n25502500\n52881984\n60481729\n99980001");
                }
                else    {
                }
            }
        }
    }
}
Thank you for your help

sauronnikko
New poster
Posts: 2
Joined: Thu Dec 25, 2008 12:35 am

Re: 256 - Runtime Error

Post by sauronnikko »

Well, now it's getting stranger. I wrote the same code, this time in C++. Here it is:

Code: Select all

#include <iostream>
using namespace std;

int main ()     {
    while (true) {
          int digits;
          cin >> digits;
          if (digits != 2 && digits != 4 && digits != 6 && digits != 8) {
                break;
          }
          else {
               if (digits == 2)     {
                    cout << "00\n01\n81\n";
               }
               else if (digits == 4)  {
                    cout << "0000\n0001\n2025\n3025\n9801\n";
               }
               else if (digits == 6)  {
                    cout << "000000\n000001\n088209\n494209\n998001\n";
               }
               else if (digits == 8)  {
                    cout << "00000000\n00000001\n04941729\n07441984\n24502500\n25502500\n52881984\n60481729\n99980001\n";
               }
               else {break;}
          }
    }
    return 0;
}
And now I'm getting TLE! I don't understand how that's even possible. Any suggestion can help. Thanks

Aumy
New poster
Posts: 2
Joined: Sat Mar 21, 2009 7:05 am

Re: 256 - Runtime Error

Post by Aumy »

you wrote while (true) ... this caused runtime err for u
just change it to (while (cin >> digits){ ....}) u will get AC. :D

SDiZ
New poster
Posts: 13
Joined: Fri Aug 05, 2005 12:20 pm
Location: Hong Kong
Contact:

256, malformed judge input?

Post by SDiZ »

The test data is okay if I use

Code: Select all

while ((cin >> n)) {
 ...
}
but not

Code: Select all

while (1) {
   cin >> n;
   if (cin.eof()) break;

   ...
}
is this expected?

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

Re: 256..............another piece of cake?

Post by uDebug »

peluso wrote:I too do not know why I'm getting WA. Can anyone see what's wrong?
The output you posted is AC.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

Post Reply

Return to “Volume 2 (200-299)”