Page 2 of 3
Posted: Tue Aug 03, 2004 10:12 am
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).
Posted: Tue Aug 03, 2004 11:45 pm
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]
256 - Quirksome Squares
Posted: Wed Jan 18, 2006 7:32 pm
by dmc
problem solved
256~Output Limit Exceeded(help><")
Posted: Thu Jun 15, 2006 4:46 am
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?
Posted: Thu Jun 15, 2006 5:36 pm
by the LA-Z-BOy
You are getting Output Limit Exceeded because your program doesn't break the loop. Your condition is
scanf returns EOF(equivalent to -1) on end-of-file / error, not ZERO.
so it could be written as
or
or
256 WA
Posted: Sun Aug 20, 2006 9:29 pm
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!
Posted: Sat Aug 26, 2006 1:49 am
by daveon
Hi,
input: 6 -> 5 values in output
input: 8 -> 9 values in output
Re: 256..............another piece of cake?
Posted: Wed Apr 09, 2008 12:22 pm
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
Re: 256..............another piece of cake?
Posted: Wed Apr 09, 2008 12:34 pm
by Obaida
Ok... I got Acc.. That was a bad mistake...

Re: 256..............another piece of cake?
Posted: Mon Sep 22, 2008 5:13 am
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
256 - Runtime Error
Posted: Fri Apr 10, 2009 11:53 pm
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
Re: 256 - Runtime Error
Posted: Sat Apr 11, 2009 9:44 pm
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
Re: 256 - Runtime Error
Posted: Wed Jul 29, 2009 8:09 am
by Aumy
you wrote while (true) ... this caused runtime err for u
just change it to (while (cin >> digits){ ....}) u will get AC.

256, malformed judge input?
Posted: Tue Mar 01, 2011 10:16 am
by SDiZ
The test data is okay if I use
but not
Code: Select all
while (1) {
cin >> n;
if (cin.eof()) break;
...
}
is this expected?
Re: 256..............another piece of cake?
Posted: Sat Apr 05, 2014 1:45 pm
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.