621 - Secret Research
Moderator: Board moderators
621 help me plz
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]
[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]
sample input:
output should be:
hint : use if else so not every if will executed
Code: Select all
1
19000035
output should be:
Code: Select all
-
hint : use if else so not every if will executed
621
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).
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.
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
my program says:
19035 => -
3 => -
94 => *
190 => ?
123 => ignored and not output anything
Best regards
DM
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)
Born from ashes - restarting counter of problems (800+ solved problems)
621 - Runtime Error (SIGSEGV)
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
/* @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
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
[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]
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:](./images/smilies/icon_wink.gif)
[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]
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
OUTPUT
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
+
-
?
*
*
-
-
*
?
?
621got RUNTIME ERROR
this is my code but i got runtime error
i withdrawed my code
i withdrawed my code
Last edited by sv90 on Thu Feb 09, 2006 2:09 pm, edited 1 time in total.
-
- Experienced poster
- Posts: 122
- Joined: Sun Nov 13, 2005 10:25 am
- Location: Taiwan
Re: ACM 621
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.Ming Han wrote:What if you have something like "12345".
Thank You
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
Hope it will work
so no need to find out "1","4" or "78".
To Dejarik, you have written
meaning you are searching when the value is '78'.else if(lon>1){ }
Hope it will work
-
- Learning poster
- Posts: 62
- Joined: Sun Jul 09, 2006 8:31 am
- Location: University of Dhaka
- Contact:
-
- New poster
- Posts: 8
- Joined: Mon Jan 22, 2007 9:08 pm
Hi
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
I have followed the logic of checking for +,-,*,? in order.
Can you tell me where else the logic could have gone wrong?
thanks,
Vichu