743 - The MTM Machine

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

Moderator: Board moderators

Post Reply
ayaw
New poster
Posts: 18
Joined: Fri May 23, 2003 3:52 pm
Contact:

743 - The MTM Machine

Post by ayaw » Fri Jun 13, 2003 9:53 am

anyone can give me more sample input??
and the output of course :)

i'm still confused with the 3rd rule :)

-thanks-
peace...

User avatar
UFP2161
A great helper
Posts: 277
Joined: Mon Jul 21, 2003 7:49 pm
Contact:

Post by UFP2161 » Tue Oct 07, 2003 6:30 am

If you can understand the last example, you should be able to understand rule number 3.

What does 33289 produce?
- What does 3289 produce?
-- What does 289 produce?
--- 89
-- 289 produces 89, so 3289 produces the associate of 89 or 89289
- 3289 produces 89289, so 33289 produces the associate of 89289 or 89289289289

technobug
Learning poster
Posts: 88
Joined: Sat Nov 15, 2003 6:41 pm
Location: Brasilien
Contact:

Post by technobug » Thu Feb 10, 2005 12:32 am

I have implemented all rules and cant get it right, tried a lot of input and i think its ok.
It should be an easy one...

Any suggestions?

Code: Select all

#include <iostream>
#include <string>

using namespace std;

bool b;

string parse(string s,int len) {

	if(s[0]=='2' && len==1) goto bz;
	if(s[0]=='2') return s.substr(1,len-1);
	if(s[0]=='3' && len==1) goto bz;
	if(s[0]=='3') {
		string z = parse(s.substr(1,len-1),len-1);
		return z + "2" + z;
	}

bz:
	b = false; return "";

}

int main() {

	string s;
	while((cin >> s)) {
		if(s[0]=='0' && (s[1]=='\n' || s[1]=='\r' || s[1]=='\0')) break;
		int len = s.size();
		b = true;
		for(int i=0;i!=len;i++) if(s[i]=='0') goto iz;
		s = parse(s,s.size());
		if(!b) goto iz;
		cout << s << endl;
continue;
	iz:cout<< "NOT ACCEPTABLE" << endl;
	}
	return 0;

}

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan » Fri Apr 21, 2006 6:54 am

Just one error...

Input:

Code: Select all

2222
0
Output

Code: Select all

2
Hope it helps.
Ami ekhono shopno dekhi...
HomePage

Raiyan Kamal
Experienced poster
Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm
Location: Bangladesh
Contact:

Post by Raiyan Kamal » Fri Oct 27, 2006 8:14 am

I dont think so , Jan. The rule said, 2X will produce X. So 2222 should produce 222. For every string containing no '0' and starting with '2' , the output shall be the resulting string found by removing the '2' at the beginning.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan » Fri Oct 27, 2006 2:40 pm

Raiyan Kamal wrote:I dont think so , Jan. The rule said, 2X will produce X. So 2222 should produce 222. For every string containing no '0' and starting with '2' , the output shall be the resulting string found by removing the '2' at the beginning.
I think you have misunderstood something. The problem states...
Rule 1:
Given any number X not containing a digit zero, then number 2X produces X. For example, 234 produces 34.
Suppose you have

Code: Select all

   2222
=> 2X (where X = 222)
=> X (Rule 1)
=> 222 (The value of X)
=> 2X (where X = 22)
=> X
=> 22
=> 2X (where X = 2)
=> X
=> 2
Thats why the answer should be 2.
Ami ekhono shopno dekhi...
HomePage

asif_rahman0
Experienced poster
Posts: 209
Joined: Sun Jan 16, 2005 6:22 pm

Post by asif_rahman0 » Fri Oct 27, 2006 5:21 pm

Hi technobug,
i think you program doesn't give correct output for the following input:

Code: Select all

22225
225
check it out.
bye

Raiyan Kamal
Experienced poster
Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm
Location: Bangladesh
Contact:

Post by Raiyan Kamal » Sun Oct 29, 2006 5:44 pm

There is no rule saying that you have to do recursive calculation with X in the cases like 2X. And I did not code my program ( whic produced an AC long ago ) that way. My prog gives 222 if input is 2222.

User avatar
kunigas
New poster
Posts: 4
Joined: Mon Feb 26, 2007 4:29 am

Post by kunigas » Mon Feb 26, 2007 4:39 am

Yeah, I think

Code: Select all

2222
should output

Code: Select all

222
Rule 3 says you have to do Y2Y, and Y is a product from a number X. So the recursion is necessary.

If rule 2 required recursion, I think it should state something like this:
2X produces Y where X produces Y.

Imti
Learning poster
Posts: 53
Joined: Sat Dec 04, 2010 12:00 pm
Location: Bangladesh
Contact:

Re: 743 - The MTM Machine

Post by Imti » Tue Feb 01, 2011 10:59 am

I'm getting WA.Please verify anyone my output's with accepted code:
Input
323289
22225
232323
0001
Output

Code: Select all

89289289289
5
3232323
NOT ACCEPTABLE

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Re: 743 - The MTM Machine

Post by helloneo » Tue Feb 01, 2011 6:24 pm

Input:

Code: Select all

323289
22225
232323
0001
0
My AC code returns

Code: Select all

328923289
2225
32323
NOT ACCEPTABLE

Imti
Learning poster
Posts: 53
Joined: Sat Dec 04, 2010 12:00 pm
Location: Bangladesh
Contact:

Re: 743 - The MTM Machine

Post by Imti » Thu Feb 03, 2011 9:51 am

Thnx Helloneo...
I misunderstood the problem.I was checking from the end of number and repeating the process recursively as Jan explained.For example:For input 323289
at first i found x=289 which results Y=89 and as according to rule 3 it produces 89289 .So number becomes 3289289...recursively again I got X=289289 which results Y=89289 and finally again from rule 3 i got the final output 89289289289.That's the way i worked.But got that my approach is wrong...Please can u explain how 33289 produces 89289289289
Tn\hnx again

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Re: 743 - The MTM Machine

Post by helloneo » Fri Feb 04, 2011 4:01 pm

Imti wrote:Thnx Helloneo...
I misunderstood the problem.I was checking from the end of number and repeating the process recursively as Jan explained.For example:For input 323289
at first i found x=289 which results Y=89 and as according to rule 3 it produces 89289 .So number becomes 3289289...recursively again I got X=289289 which results Y=89289 and finally again from rule 3 i got the final output 89289289289.That's the way i worked.But got that my approach is wrong...Please can u explain how 33289 produces 89289289289
Tn\hnx again
Well, the example of 33289 is pretty much explained by UFP2161..
See the previous post..

BTW, for the input 323289, I think x = 3289, not 289. Which means 323289 => 3(23289) => 3(2(3289)) => 3(3289) => 328923289

Post Reply

Return to “Volume 7 (700-799)”