10182 - Bee Maja
Moderator: Board moderators
10182 - Bee Maja
i always get compile error as reply.. can any one tell me how to handle this? is it because my program is too long? plz reply thiz post.. thx..
@begin_of_source_code
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INPUTFILE "BEEMAJA.IN"
#define OUTPUTFILE "BEEMAJA.OUT"
FILE *finput;
FILE *foutput;
void BeeMaja(int *k1, int *k2, long number) {
long c,test;
int n,i;
int p1,p2;
int up;
c=1;
n=1;
p1=p2=0;
while (c < number) {
c+=(n*6);
n++;
p1++;
}
for (i=1;i<n;i++) {
c--;
p2--;
if (c==number) goto ketemu;
}
for (i=1;i<n;i++) {
c--;
p1--;
if (c==number) goto ketemu;
}
for (i=1;i<n;i++) {
c--;
p1--;
p2++;
if (c==number) goto ketemu;
}
for (i=1;i<n;i++) {
c--;
p2++;
if (c==number) goto ketemu;
}
for (i=1;i<n;i++) {
c--;
p1++;
//p2++;
if (c==number) goto ketemu;
}
for (i=1;i<n;i++) {
c--;
p1++;
p2--;
if (c==number) goto ketemu;
}
ketemu:
*k1 = p1;
*k2 = p2;
}
void main () {
int m,n,i;
char input[10];
long number;
char ch[2];
printf("Bee Maja\n");
printf("========\n\n\n");
printf("Open input file %s...\n",INPUTFILE);
finput = fopen(INPUTFILE,"rt");
if (finput == NULL) {
printf("Open File Fail.\n");
exit(EXIT_FAILURE);
}
printf("Open File Success.\n\n");
printf("Open output file %s...\n",INPUTFILE);
foutput = fopen(OUTPUTFILE,"wt");
if (foutput == NULL) {
printf("Open File Fail.\n");
exit(EXIT_FAILURE);
}
printf("Open File Success.\n\n");
printf("Processing input file...\n");
while (1) {
input[0]='\0';
if (fgets(ch,2,finput)==NULL) break;
i=0;
while (1) {
if (i<=10) input=ch[0];
if (fgets(ch,2,finput)==NULL) break;
if (ch[0] == '\n') {
break;
}
i++;
}
input[i+1]='\0';
if (strlen(input) > 0) {
printf(" input : %s ",input);
number = atol(input);
BeeMaja (&m,&n,number);
fprintf(foutput,"%d,%d\n",m,n);
printf(" -->done. output : %d,%d\n",m,n);
}
}
printf("Processing completed\n");
fclose(finput);
fclose(foutput);
}
@end_of_source_code
@begin_of_source_code
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INPUTFILE "BEEMAJA.IN"
#define OUTPUTFILE "BEEMAJA.OUT"
FILE *finput;
FILE *foutput;
void BeeMaja(int *k1, int *k2, long number) {
long c,test;
int n,i;
int p1,p2;
int up;
c=1;
n=1;
p1=p2=0;
while (c < number) {
c+=(n*6);
n++;
p1++;
}
for (i=1;i<n;i++) {
c--;
p2--;
if (c==number) goto ketemu;
}
for (i=1;i<n;i++) {
c--;
p1--;
if (c==number) goto ketemu;
}
for (i=1;i<n;i++) {
c--;
p1--;
p2++;
if (c==number) goto ketemu;
}
for (i=1;i<n;i++) {
c--;
p2++;
if (c==number) goto ketemu;
}
for (i=1;i<n;i++) {
c--;
p1++;
//p2++;
if (c==number) goto ketemu;
}
for (i=1;i<n;i++) {
c--;
p1++;
p2--;
if (c==number) goto ketemu;
}
ketemu:
*k1 = p1;
*k2 = p2;
}
void main () {
int m,n,i;
char input[10];
long number;
char ch[2];
printf("Bee Maja\n");
printf("========\n\n\n");
printf("Open input file %s...\n",INPUTFILE);
finput = fopen(INPUTFILE,"rt");
if (finput == NULL) {
printf("Open File Fail.\n");
exit(EXIT_FAILURE);
}
printf("Open File Success.\n\n");
printf("Open output file %s...\n",INPUTFILE);
foutput = fopen(OUTPUTFILE,"wt");
if (foutput == NULL) {
printf("Open File Fail.\n");
exit(EXIT_FAILURE);
}
printf("Open File Success.\n\n");
printf("Processing input file...\n");
while (1) {
input[0]='\0';
if (fgets(ch,2,finput)==NULL) break;
i=0;
while (1) {
if (i<=10) input=ch[0];
if (fgets(ch,2,finput)==NULL) break;
if (ch[0] == '\n') {
break;
}
i++;
}
input[i+1]='\0';
if (strlen(input) > 0) {
printf(" input : %s ",input);
number = atol(input);
BeeMaja (&m,&n,number);
fprintf(foutput,"%d,%d\n",m,n);
printf(" -->done. output : %d,%d\n",m,n);
}
}
printf("Processing completed\n");
fclose(finput);
fclose(foutput);
}
@end_of_source_code
10182-Bee problem
I simply generated the whole table for the maximum size.
and after reading a number print positionX[number],positionY[number].
got wrong ans.
please give me some I/O.
and after reading a number print positionX[number],positionY[number].
got wrong ans.
please give me some I/O.
10182 - bee maja
Can anyone give me any hint on this?
Is there a simple formula?
Is there a simple formula?
-
- Experienced poster
- Posts: 106
- Joined: Thu Jan 29, 2004 12:07 pm
- Location: Bangladesh
- Contact:
10182-BeeMaja
I have been trying to submit this code for the past few days but every time it shows the same error- WRONG OUTPUT.I am new at uva. Plz help me find what has gone wrong in the code as I am not able to see what is wrong with it.
#include<iostream>
#include<list>
using namespace std;
int main(){
list<int> l;
list<int>::iterator I;
int n;
while(1){
cin>>n;
if(n==EOF) break;
int a=6,b=1;
n--;
while(n>a){
n-=b*6;
a=(b+1)*6;
b++;
}
int k1=(n-1)/b,k2=(n-1)%b,x=0,y=0;
//cout<<b<<" "<<n<<"\n";
switch(k1){
case 0:
x=b-(1+k2);
y=k2+1;
break;
case 1:
x=-(k2+1);
y=b;
break;
case 2:
x=-b;
y=b-(k2+1);
break;
case 3:
x=k2+1-b;
y=-(k2+1);
break;
case 4:
x=k2+1;
y=-b;
break;
case 5:
x=b;
y=k2+1-b;
break;
}
//cout<<x<<" "<<y<<endl;
l.push_back(x);l.push_back(y);
}
for(I=l.begin();I!=l.end();I++){
cout<<*I<<" ";
I++;
cout<<*I<<"\n";
}
return 0;
}
#include<iostream>
#include<list>
using namespace std;
int main(){
list<int> l;
list<int>::iterator I;
int n;
while(1){
cin>>n;
if(n==EOF) break;
int a=6,b=1;
n--;
while(n>a){
n-=b*6;
a=(b+1)*6;
b++;
}
int k1=(n-1)/b,k2=(n-1)%b,x=0,y=0;
//cout<<b<<" "<<n<<"\n";
switch(k1){
case 0:
x=b-(1+k2);
y=k2+1;
break;
case 1:
x=-(k2+1);
y=b;
break;
case 2:
x=-b;
y=b-(k2+1);
break;
case 3:
x=k2+1-b;
y=-(k2+1);
break;
case 4:
x=k2+1;
y=-b;
break;
case 5:
x=b;
y=k2+1-b;
break;
}
//cout<<x<<" "<<y<<endl;
l.push_back(x);l.push_back(y);
}
for(I=l.begin();I!=l.end();I++){
cout<<*I<<" ";
I++;
cout<<*I<<"\n";
}
return 0;
}
-
- New poster
- Posts: 1
- Joined: Fri Nov 13, 2009 11:34 am
10182- Bee Maja Runtime Error
Hi,
I've been getting Runtime Errors for the Bee Maja problem. I cannot figure out what I am doing wrong though. Any suggestions?
I've been getting Runtime Errors for the Bee Maja problem. I cannot figure out what I am doing wrong though. Any suggestions?
Code: Select all
import java.util.Scanner;
class BeeMaja
{
public static void main(String[] args) throws Exception
{
Scanner in = new Scanner(System.in);
while(in.hasNextInt())
{
int coord = in.nextInt();
int[] resultCoord = convertCoord(coord);
System.out.println(resultCoord[0]+ " " + resultCoord[1]);
}
in.close();
System.exit(0);
return;
}
private static int[] convertCoord(int coord)
{
int[] converted = new int[2];
int ringNumber = 0, i;
for(i = 0; 6 * i + 1 < coord; i+=ringNumber)
{
ringNumber ++;
}
int ringMax = 6 * i + 1;
converted[0] = ringNumber;
for(i = 0; i < ringNumber && ringMax > coord; i++)
{
converted[1]--;
ringMax--;
}
for(i = 0; i < ringNumber && ringMax > coord; i++)
{
converted[0]--;
ringMax--;
}
for(i = 0; i < ringNumber && ringMax > coord; i++)
{
converted[0]--;
converted[1]++;
ringMax--;
}
for(i = 0; i < ringNumber && ringMax > coord; i++)
{
converted[1]++;
ringMax--;
}
for(i = 0; i < ringNumber && ringMax > coord; i++)
{
converted[0]++;
ringMax--;
}
for(i = 0; i < ringNumber && ringMax > coord; i++)
{
converted[0]++;
converted[1]--;
ringMax--;
}
return converted;
}
}