256 - Quirksome Squares
Moderator: Board moderators
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).
[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).
-
- Guru
- Posts: 1080
- Joined: Thu Dec 19, 2002 7:37 pm
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]
[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~Output Limit Exceeded(help><")
#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?
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?
-
- Learning poster
- Posts: 94
- Joined: Wed Jul 31, 2002 12:44 pm
- Location: Dacca, Bangladesh
- Contact:
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
Code: Select all
while(scanf("%d",&c)!=0){
so it could be written as
Code: Select all
while(scanf("%d",&c)!=-1){
Code: Select all
while(scanf("%d",&c)!=EOF){
Code: Select all
while(scanf("%d",&c)==1){
Istiaque Ahmed [the LA-Z-BOy]
256 WA
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!
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!

Re: 256..............another piece of cake?
Some one Please check my input & output... What's wrong I am getting WA>..
Input
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.
This may be the address of success.
Re: 256..............another piece of cake?
Ok... I got Acc.. That was a bad mistake... 

try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.
Re: 256..............another piece of cake?
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
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
-
- New poster
- Posts: 2
- Joined: Thu Dec 25, 2008 12:35 am
256 - Runtime Error
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
Thank you for your help
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 {
}
}
}
}
}
-
- New poster
- Posts: 2
- Joined: Thu Dec 25, 2008 12:35 am
Re: 256 - Runtime Error
Well, now it's getting stranger. I wrote the same code, this time in C++. Here it is:
And now I'm getting TLE! I don't understand how that's even possible. Any suggestion can help. Thanks
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;
}
Re: 256 - Runtime Error
you wrote while (true) ... this caused runtime err for u
just change it to (while (cin >> digits){ ....}) u will get AC.
just change it to (while (cin >> digits){ ....}) u will get AC.

256, malformed judge input?
The test data is okay if I use
but not
is this expected?
Code: Select all
while ((cin >> n)) {
...
}
Code: Select all
while (1) {
cin >> n;
if (cin.eof()) break;
...
}
Re: 256..............another piece of cake?
The output you posted is AC.peluso wrote:I too do not know why I'm getting WA. Can anyone see what's wrong?