621 - Secret Research

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

Moderator: Board moderators

problem
New poster
Posts: 27
Joined: Mon Nov 10, 2003 12:40 am

621 help me plz

Post by problem » Tue Nov 25, 2003 12:11 pm

seems very simple.but wa.i m frustrated.plz rescue me.

[c]

#include<stdio.h>
#include<math.h>
#include<string.h>
#define max 10000
void main()
{
char t[max];
long int i,j,l;
scanf("%ld",&j);
for(l=0;l<=j;l++)
{
gets(t);
i=strlen(t);
if(t[0]=='1'&&t[1]=='9'&&t[2]=='0')
printf("?\n");
if(t[i-1]=='5'&&t[i-2]=='3')
printf("-\n");
if(t[0]=='9'&&t[i-1]=='4')
printf("*\n");
if(i==2&&t[0]=='7'&&t[1]=='8')
printf("+\n");
if(i==1&&t[0]=='1'||t[0]=='4')
printf("+\n");
}
}
[\c]

deddy one
Experienced poster
Posts: 120
Joined: Tue Nov 12, 2002 7:36 pm

Post by deddy one » Tue Nov 25, 2003 1:09 pm

sample input:

Code: Select all

1
19000035

output should be:

Code: Select all

-

hint : use if else so not every if will executed

ttjasi
New poster
Posts: 1
Joined: Tue Feb 10, 2004 10:50 pm

621

Post by ttjasi » Tue Feb 10, 2004 10:57 pm

http://acm.uva.es/p/v6/621.html

What is the output for the following inputs?

19035 - (Reportedly, use '-' from the other posts)

35 - Doesn't match S35 unless S can be blank
94 - Doesn't match 9S4 unless S can be blank
190 - Doesn't match 190S unless S can be blank

123 - Matches no criteria

I keep getting Wrong Answer despite every combination I use. Am I missing something?

-

Reporting '*' for all of the non-matching criteria above, I received WA. At the end of every output, I had an end line statement. I removed the very last one and it gives me AC(PE).
Last edited by ttjasi on Thu Feb 12, 2004 10:05 pm, edited 2 times in total.

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski » Wed Feb 11, 2004 9:23 am

my program says:
19035 => -
3 => -
94 => *
190 => ?
123 => ignored and not output anything

Best regards
DM
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)

keceman
New poster
Posts: 7
Joined: Wed Mar 03, 2004 6:51 am

621 - Runtime Error (SIGSEGV)

Post by keceman » Wed Mar 03, 2004 1:54 pm

Hi... I wonder why my source is said runtime error?? and the error message is invalid memory indirection or something like that.... i don't get it.. i compile and run it under Turbo C++ 3.0 and it works fine.... anyone could help me??

/* @JUDGE_ID: 43238WF 621 C++ */

#include <iostream.h>

class Number
{
private:
char *num;
int length;
public:
Number() {};
~Number() { delete [] num; };
void setNum(char *num, int length);
char* getNum();
char process();
};

void Number::setNum(char *num, int length)
{
int x;
this->num = new char[length];
for (x=0;x<length;x++)
{
this->num[x]=num[x];
}
this->num[x]='\0';
this->length = length;
}

char* Number::getNum()
{
return num;
}

char Number::process()
{
int x=0;
switch (length)
{
case 1:
{
if (num[0] == '1') return '+';
if (num[0] == '4') return '+';
}
case 2: if (num[0] == '7' && num[1] == '8') return '+';
default:
{
if (length > 2)
{
if (num[length-2] == '3' && num[length-1] == '5') return '-';
else if (num[0] == '9' && num[length-1]== '4') return '*';
else if (num[0] == '1' && num[1] == '9' && num[2] == '0') return '?';
}
}
}
return 0;
}

void main()
{
char *nomernya;
int len, x, a;
cin >> x;
Number *nomer;
nomer = new Number[x];

for (a=0;a<x;a++)
{
nomernya = new char[32];
nomernya[0]='\0';
cin >> nomernya;
for (len=0;nomernya[len];len++);
nomer[a].setNum(nomernya, len);
delete [] nomernya;
}
for (a=0;a<x;a++)
{
cout << nomer[a].process() << endl;
}
delete [] nomer;
}


thaaaaaaaaaaaaaankzzz

Dejarik
New poster
Posts: 32
Joined: Sun Mar 07, 2004 1:23 pm
Location: Barcelona, SPAIN
Contact:

Post by Dejarik » Mon Mar 08, 2004 1:21 am

my code also gives runtime error and i don't know where should be our mistake.

i'll post the code:

Possible problems:
a) How do you usually read lines? I'm used to manage gets() function. And, in this problem, i convert these lines in integers with atoi() function.
b) How do you manage blank lines?
c) What are your answer for non-matched tests? (Like '3','222',...)

Thanks in advance :wink:

[c]#include <stdio.h>
int main(){
int nrounds;
int nr;
int num;
int lon;
char line[50];
gets(line);
nrounds=atoi(line);
for(nr=0;nr<nrounds;nr++){
gets(line);
lon=0;
num=atoi(line);
sprintf(line,"%d",num);
lon=strlen(line);
if((strcmp(line,"1")==0)||(strcmp(line,"4")==0)||(strcmp(line,"78")==0)) printf("+\n");
else if(lon>1){
if((line[lon-2]=='3')&&(line[lon-1]=='5')) printf("-\n");
else if((line[0]=='9')&&(line[lon-1]=='4')) printf("*\n");
else if(lon>2){
if((line[0]=='1')&&(line[1]=='9')&&(line[2]=='0')) printf("?\n");
}
}
}
}[/c]

User avatar
Sedefcho
A great helper
Posts: 374
Joined: Sun Jan 16, 2005 10:18 pm
Location: Bulgaria

Post by Sedefcho » Fri May 27, 2005 4:19 pm

Below is some sample I/O from a program which gets Accepted (P.E.)

Hope this I/O might be helpful to someone.

In cases where there is no match to any of the patterns
mentioned in the problem description I just print a blank line
in the output. This is not the reason for the P.E. though. I tried
also not to print anything to the output in such cases but
with that approach I also get P.E.


INPUT

Code: Select all

12
78
7835
19078
944
222
944
19035
35
94
190
123
1902

OUTPUT

Code: Select all

+
-
?
*

*
-
-
*
?

?

sv90
New poster
Posts: 17
Joined: Wed Feb 01, 2006 8:27 pm
Location: Dhaka,Bangladesh

621got RUNTIME ERROR

Post by sv90 » Mon Feb 06, 2006 4:40 pm

this is my code but i got runtime error
i withdrawed my code
Last edited by sv90 on Thu Feb 09, 2006 2:09 pm, edited 1 time in total.

Wei-Ming Chen
Experienced poster
Posts: 122
Joined: Sun Nov 13, 2005 10:25 am
Location: Taiwan

Post by Wei-Ming Chen » Tue Feb 07, 2006 3:35 pm

char str[100]; ......

My code was char s [100] also got RTE
But I changed it to char a[10000], it AC :P

sv90
New poster
Posts: 17
Joined: Wed Feb 01, 2006 8:27 pm
Location: Dhaka,Bangladesh

Post by sv90 » Thu Feb 09, 2006 2:10 pm

thanks i got acc but PE

jjtse
Learning poster
Posts: 80
Joined: Mon Aug 22, 2005 7:32 pm
Location: Nevada, US
Contact:

Re: ACM 621

Post by jjtse » Sun Jun 04, 2006 5:24 am

Ming Han wrote:What if you have something like "12345".

Thank You
based on the other posts I've read, you should print a newLine for that case, since it doesn't fit into any of the description.

WRJ
New poster
Posts: 11
Joined: Sun Mar 19, 2006 8:28 pm

Post by WRJ » Tue Aug 22, 2006 10:22 am

1) In cases where there is no match to any of the patterns
mentioned in the problem description DON'T print a blank line
2) Dont' print eoln at the end of output

marif
New poster
Posts: 11
Joined: Sat Jun 24, 2006 11:42 am
Location: BANGLADESH
Contact:

Post by marif » Fri Aug 25, 2006 4:39 pm

This is a very simple problem. Look, when string length is 1 or 2 it is directly showing '+' and others are coming only when length is greater then 2.
so no need to find out "1","4" or "78".
To Dejarik, you have written
else if(lon>1){ }
meaning you are searching when the value is '78'.

Hope it will work

User avatar
Debashis Maitra
Learning poster
Posts: 62
Joined: Sun Jul 09, 2006 8:31 am
Location: University of Dhaka
Contact:

Post by Debashis Maitra » Wed Dec 20, 2006 6:22 pm

WRJ is realy right

i modified my code and got AC

Thnx every one
Akash chhoyar swopno
Dream to touch the sky

Viswanathan V
New poster
Posts: 8
Joined: Mon Jan 22, 2007 9:08 pm

Hi

Post by Viswanathan V » Mon Jan 22, 2007 9:11 pm

I compared my output with the ones discussed above and all coincide.Yet I get WA.
I have followed the logic of checking for +,-,*,? in order.
Can you tell me where else the logic could have gone wrong?
thanks,
Vichu

Post Reply

Return to “Volume 6 (600-699)”