448 - OOPS!

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

Moderator: Board moderators

PMNOX
New poster
Posts: 49
Joined: Wed Feb 13, 2002 2:00 am
Location: Poland
Contact:

Post by PMNOX » Wed Feb 13, 2002 10:30 pm

i don't know why my program use 484 kb of memory!!!
can u tell me why?



#include <iostream.h>

//#include <fstream.h>

//ifstream a_file("input.txt");

void wartosci()
{
bool x=false;
bool y =false;
int liczba=0;
int byte;
char tab;
cin>>tab;
byte=(int)tab-48;
if(byte>=12)
byte-=7;
if(byte >= :cool:
{
x=true;
byte-=8;
}

if(byte >= 4)
{
y=true;
byte-=4;
}

//obliczanie liczby
liczba=byte;
cin>>tab;
byte=(int)tab-48;
if(byte>=12)
byte-=7;
liczba=liczba*16 + byte;
cin>>tab;
byte=(int)tab-48;
if(byte>=12)
byte-=7;
liczba=liczba*16 + byte;
cin>>tab;
byte=(int)tab-48;
if(byte>=12)
byte-=7;
liczba=liczba*16 + byte;
if((x==false) && (y==false))
cout<<"R"<<liczba;
if((x==false) && (y==true))
cout<<"$"<<liczba;
if((x==true) && (y==false))
cout<<"PC+"<<liczba;
if((x==true) && (y==true))
cout<<liczba;
}

int main()
{
char what;
while(cin>>what)
{
switch (what)
{
case '0':
cout<<"ADD ";
wartosci();
cout<<",";
wartosci();
cout<<endl;
break;
case '1':
cout<<"SUB ";
wartosci();
cout<<",";
wartosci();
cout<<endl;
break;
case '2':
cout<<"MUL ";
wartosci();
cout<<",";
wartosci();
cout<<endl;
break;
case '3':
cout<<"DIV ";
wartosci();
cout<<",";
wartosci();
cout<<endl;
break;
case '4':
cout<<"MOV ";
wartosci();
cout<<",";
wartosci();
cout<<endl;
break;
case '5':
cout<<"BREQ ";
wartosci();
cout<<endl;
break;
case '6':
cout<<"BRLE ";
wartosci();
cout<<endl;
break;
case '7':
cout<<"BRLS ";
wartosci();
cout<<endl;
break;
case '8':
cout<<"BRGE ";
wartosci();
cout<<endl;
break;
case '9':
cout<<"BRGR ";
wartosci();
cout<<endl;
break;
case 'A':
cout<<"BRNE ";
wartosci();
cout<<endl;
break;
case 'B':
cout<<"BR ";
wartosci();
cout<<endl;
break;
case 'C':
cout<<"AND ";
wartosci();
cout<<",";
wartosci();
cout<<",";
wartosci();
cout<<endl;
break;
case 'D':
cout<<"OR ";
wartosci();
cout<<",";
wartosci();
cout<<",";
wartosci();
cout<<endl;
break;
case 'E':
cout<<"XOR ";
wartosci();
cout<<",";
wartosci();
cout<<",";
wartosci();
cout<<endl;
break;
case 'F':
cout<<"NOT";
wartosci();
cout<<endl;
break;
}
}
return 0;
}

Ilham Kurnia
New poster
Posts: 31
Joined: Sat Nov 17, 2001 2:00 am
Contact:

Post by Ilham Kurnia » Thu Feb 14, 2002 12:25 pm

well, if your program runs longer than 0.100, it is more likely to get memory usage > 64 Kb.
I'm guessing that it has to do with the online judge software itself.

<font size=-1>[ This Message was edited by: Ilham Kurnia on 2002-02-14 11:26 ]</font>

FlyDeath
Learning poster
Posts: 73
Joined: Wed Jan 02, 2002 2:00 am
Location: Taiwan

Post by FlyDeath » Wed Mar 20, 2002 4:05 pm

Is there any special test case for this question?
Here is my code,but I think it's no need.


Code: Select all

#include <stdio.h>
#include <string.h>

void change(char tmp,char* out)
{
	int i=0;
	if(tmp>=48&&tmp<=57)
		tmp=tmp-48;
	else
		tmp=tmp-55;
	for(i=0;i<4;i++)
	{
		out[3-i]=(int)tmp%2;
		tmp=(int)tmp/2;
	}
}

void main()
{
	char temp[50];
	char bi[5];
	int left=0;
	int count=0;
	int flag=0;
	int ln=0;
	int lv=0;
	int full=0;
	char type;
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	while(scanf("%s",&temp)!=EOF)
	{
		count=0;
		if(left==1)
		{
			if(temp[count]>=48&&temp[count]<=57)
				ln=ln*16+temp[count]-48;
			else
				ln=ln*16+temp[count]-55;
			count++;
			printf("%d",ln);
			left=0;
			lv--;
			if(lv==0)
				printf("n");
		}
		else if(left==2)
		{
			if(temp[count]>=48&&temp[count]<=57)
				ln=ln*16+temp[count]-48;
			else
				ln=ln*16+temp[count]-55;
			count++;
			if(temp[count]>=48&&temp[count]<=57)
				ln=ln*16+temp[count]-48;
			else
				ln=ln*16+temp[count]-55;
			count++;
			printf("%d",ln);
			left=0;
			lv--;
			if(lv==0)
				printf("n");
		}
		else if(left==3)
		{
			if(temp[count]>=48&&temp[count]<=57)
				ln=ln*16+temp[count]-48;
			else
				ln=ln*16+temp[count]-55;
			count++;
			if(temp[count]>=48&&temp[count]<=57)
				ln=ln*16+temp[count]-48;
			else
				ln=ln*16+temp[count]-55;
			count++;
			if(temp[count]>=48&&temp[count]<=57)
				ln=ln*16+temp[count]-48;
			else
				ln=ln*16+temp[count]-55;
			count++;
			left=0;
			lv--;
			if(lv==0)
				printf("n");
		}
		while(lv!=0)
		{
			change(temp[count],bi);
			flag=bi[0]*2+bi[1];
			if(flag==3&&lv==1&&((type<='4'||type>='C')||type=='F'))
			{
				lv=0;
				printf("n");
				break;
			}
			if((flag==3||flag==0)&&(type>='5'&&type<='B'))
			{
				lv=0;
				printf("n");
				break;
			}
			count++;
			if(lv!=full)
				printf(",");
			if(flag==0)
				printf("R");
			else if(flag==1)
				printf("$");
			else if(flag==2)
				printf("PC+");
			ln=bi[2]*2+bi[3];
			if(temp[count]>=48&&temp[count]<=57)
				ln=ln*16+temp[count]-48;
			else
				ln=ln*16+temp[count]-55;
			count++;
			if(temp[count]>=48&&temp[count]<=57)
				ln=ln*16+temp[count]-48;
			else
				ln=ln*16+temp[count]-55;
			count++;
			if(temp[count]>=48&&temp[count]<=57)
				ln=ln*16+temp[count]-48;
			else
				ln=ln*16+temp[count]-55;
			printf("%d",ln);
			count++;
			lv--;
			if(lv==0)
				printf("n");
		}
		if(count==strlen(temp))
			continue;
		while(1)
		{
			if(temp[count]=='0')
				printf("ADD ");
			else if(temp[count]=='1')
				printf("SUB ");
			else if(temp[count]=='2')
				printf("MUL ");
			else if(temp[count]=='3')
				printf("DIV ");
			else if(temp[count]=='4')
				printf("MOV ");
			else if(temp[count]=='5')
				printf("BREQ ");
			else if(temp[count]=='6')
				printf("BRLE ");
			else if(temp[count]=='7')
				printf("BRLS ");
			else if(temp[count]=='8')
				printf("BRGE ");
			else if(temp[count]=='9')
				printf("BRGR ");
			else if(temp[count]=='A')
				printf("BRNE ");
			else if(temp[count]=='B')
				printf("BR ");
			else if(temp[count]=='C')
				printf("AND ");
			else if(temp[count]=='D')
				printf("OR ");
			else if(temp[count]=='E')
				printf("XOR ");
			else if(temp[count]=='F')
				printf("NOT ");
			type=temp[count];
			if(type>=48&&type<=52)
				lv=2;
			else if((type>=53&&type<=66)||type=='F')
				lv=1;
			else
				lv=3;
			full=lv;
			count++;
			while(lv!=0)
			{
				if(count==strlen(temp))
					break;
				change(temp[count],bi);
				flag=bi[0]*2+bi[1];
				if(flag==3&&lv==1&&((type<='4'||type>='C')||type=='F'))
				{
					lv=0;
					printf("n");
					break;
				}
				if((flag==3||flag==0)&&(type>='5'&&type<='B'))
				{
					lv=0;
					printf("n");
					break;
				}
				count++;
				if(lv!=full)
					printf(",");
				if(flag==0)
					printf("R");
				else if(flag==1)
					printf("$");
				else if(flag==2)
					printf("PC+");
				ln=bi[2]*2+bi[3];
				if(count==strlen(temp))
				{
					left=3;
					break;
				}
				if(count==29)
				{
					if(temp[count]>=48&&temp[count]<=57)
						ln=ln*16+temp[count]-48;
					else
						ln=ln*16+temp[count]-55;
					count++;
					left=2;
					break;
				}
				else if(count==28)
				{
					if(temp[count]>=48&&temp[count]<=57)
						ln=ln*16+temp[count]-48;
					else
						ln=ln*16+temp[count]-55;
					count++;
					if(temp[count]>=48&&temp[count]<=57)
						ln=ln*16+temp[count]-48;
					else
						ln=ln*16+temp[count]-55;
					count++;
					left=1;
					break;
				}
				else
				{
					if(temp[count]>=48&&temp[count]<=57)
						ln=ln*16+temp[count]-48;
					else
						ln=ln*16+temp[count]-55;
					count++;
					if(temp[count]>=48&&temp[count]<=57)
						ln=ln*16+temp[count]-48;
					else
						ln=ln*16+temp[count]-55;
					count++;
					if(temp[count]>=48&&temp[count]<=57)
						ln=ln*16+temp[count]-48;
					else
						ln=ln*16+temp[count]-55;
					printf("%d",ln);
					count++;
				}
				lv--;
				if(lv==0)
					printf("n");
			}
			if(count==strlen(temp))
				break;
		}
	}
}

sjn
Learning poster
Posts: 73
Joined: Mon Apr 08, 2002 8:22 am
Contact:

p448-C++ WA~

Post by sjn » Wed Aug 14, 2002 12:54 pm

always got WA why?
can u give me some inputs and outputs?

thx in advance~

sjn
Learning poster
Posts: 73
Joined: Mon Apr 08, 2002 8:22 am
Contact:

code

Post by sjn » Wed Aug 14, 2002 1:18 pm

Maybe there is something wrong with the input
but i cannot find it :cry:
Last edited by sjn on Mon Feb 02, 2004 5:44 pm, edited 1 time in total.

sjn
Learning poster
Posts: 73
Joined: Mon Apr 08, 2002 8:22 am
Contact:

Post by sjn » Thu Aug 15, 2002 12:33 pm

i have pass 448 by pascal
so i think there must be something wrong with the input
can anybody help me? :cry:

liusu
New poster
Posts: 22
Joined: Thu Aug 01, 2002 10:26 am

hi

Post by liusu » Sun Aug 18, 2002 9:39 am

so You'd better not use C++....pascal is good enougth for you :D

udvat
New poster
Posts: 29
Joined: Thu Aug 07, 2003 9:56 pm

448...............help me plz,

Post by udvat » Sat Nov 01, 2003 10:54 am

plz help me by providing some sample input/output for the problem 448"oops". :cry: tired of getting WA

User avatar
habibiamin
New poster
Posts: 8
Joined: Tue Oct 12, 2004 1:54 pm
Location: Iran-Tehran
Contact:

448 Why OLE

Post by habibiamin » Sun Oct 24, 2004 7:36 am

Can any one help me ??? Why OLE ??? 448

[cpp]
//Assembler
#include<stdio.h>

enum Mode {Register,Absoulate,PCRelative,Constant};

struct Operand
{
int Value;
Mode OprMod;
};

class HexOperand
{
private:
int Digits[5]; // 4 Digits
Operand ResultOpr;
public:
void ReadOperand()
{
char c;
for(int i=1;i<=4;i++)
{
while(scanf("%c",&c),c=='\n');
c-=48;
if(c>9)c-=7;
Digits=c;
}
}
void PrintOperand()
{
OprRecognition();
switch(ResultOpr.OprMod)
{
case Register:{printf("R");break;}
case Absoulate:{printf("$");break;}
case PCRelative:{printf("PC+");break;}
case Constant:{break;}
}
printf("%d",ResultOpr.Value);
}
private:
void OprRecognition()
{
//Recognizing The Operand Mode
if((Digits[1]&12)==0)
ResultOpr.OprMod =Register;
else if((Digits[1]&12)==4)
ResultOpr.OprMod =Absoulate;
else if((Digits[1]&12)==8)
ResultOpr.OprMod =PCRelative;
else if((Digits[1]&12)==12)
ResultOpr.OprMod =Constant;

//Calculating The Operand Value
Digits[1]=Digits[1]&3;
ResultOpr.Value =Digits[1]*4096+Digits[2]*256+Digits[3]*16+Digits[4]; //Hex 2 Dec
}

};

int CommandRecognition(char Cmd)
{
switch(Cmd)
{
case '0': {printf("ADD ");return 2;}
case '1': {printf("SUB ");return 2;}
case '2': {printf("MUX ");return 2;}
case '3': {printf("DIV ");return 2;}
case '4': {printf("MOV ");return 2;}
case '5': {printf("BREQ ");return 1;}
case '6': {printf("BRLE ");return 1;}
case '7': {printf("BRLS ");return 1;}
case '8': {printf("BRGE ");return 1;}
case '9': {printf("BRGR ");return 1;}
case 'A': {printf("BRNE ");return 1;}
case 'B': {printf("BR ");return 1;}
case 'C': {printf("AND ");return 3;}
case 'D': {printf("OR ");return 3;}
case 'E': {printf("XOR ");return 3;}
case 'F': {printf("NOT ");return 1;}
}
}

int ReadCmd(char &Cmd)
{
int r;
while(r=scanf("%c",&Cmd),Cmd=='\n'&&r!=0);
return r;
}

int main()
{
char Cmd;
HexOperand Opr1,Opr2,Opr3;
int OprCnt;
while(ReadCmd(Cmd))
{
OprCnt=CommandRecognition(Cmd);
Opr1.ReadOperand();
Opr1.PrintOperand();
if (OprCnt>1)
{
printf(",");
Opr2.ReadOperand();
Opr2.PrintOperand();
if (OprCnt>2)
{
printf(",");
Opr3.ReadOperand();
Opr3.PrintOperand();
}
}
printf("\n");

}
return 0;
}
[/cpp]

wirjawan
New poster
Posts: 16
Joined: Fri Oct 01, 2004 10:48 pm
Location: Indonesia

Post by wirjawan » Mon Oct 25, 2004 10:33 pm

Your code does not terminate when it reaches the End Of File, so
change your ReadCmd function to:

[cpp]
int
ReadCmd (char &Cmd)
{
do
{
if(scanf("%c",&Cmd)==EOF) return 0;
}while (Cmd=='\n');
return 1;
}
[/cpp]

taborda
New poster
Posts: 6
Joined: Wed Mar 16, 2005 1:57 am

448 - OOPS! - Output Limit Exceeded

Post by taborda » Wed Mar 16, 2005 2:01 am

in the test cases, and some of myself, it worked...but when submited i get "Output Limit Exceeded"

any help for this strange error???...

Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:

Post by Larry » Wed Mar 16, 2005 3:38 am

Your terminating condition could be wrong, and you might keep printing out junk..

Artikali
Learning poster
Posts: 68
Joined: Wed Sep 21, 2005 5:27 pm

448 - OOPS!

Post by Artikali » Tue Mar 07, 2006 8:09 pm

i read some topics, sjn wrote that he passed in pascal, but WA in C++
please give some tests
my input code is

Code: Select all

		if (scanf("%30[^\n]",line)!=1) ext=1;
		getchar();
thanks

Artikali
Learning poster
Posts: 68
Joined: Wed Sep 21, 2005 5:27 pm

Post by Artikali » Fri Mar 10, 2006 4:19 pm

i got AC. 0.012 second. memory minimum
But i saw statistics of this problem, and there was 0 seconds time elapsed
How can i get such a result?

Nakar
New poster
Posts: 16
Joined: Tue Apr 17, 2007 6:37 pm

448 Need test cases or trick

Post by Nakar » Sun Apr 29, 2007 11:38 am

I need test cases or one trick for this problem.

Thanks.

Post Reply

Return to “Volume 4 (400-499)”