Page 1 of 1

743 - The MTM Machine

Posted: Fri Jun 13, 2003 9:53 am
by ayaw
anyone can give me more sample input??
and the output of course :)

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

-thanks-

Posted: Tue Oct 07, 2003 6:30 am
by UFP2161
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

Posted: Thu Feb 10, 2005 12:32 am
by technobug
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;

}

Posted: Fri Apr 21, 2006 6:54 am
by Jan
Just one error...

Input:

Code: Select all

2222
0
Output

Code: Select all

2
Hope it helps.

Posted: Fri Oct 27, 2006 8:14 am
by Raiyan Kamal
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.

Posted: Fri Oct 27, 2006 2:40 pm
by Jan
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.

Posted: Fri Oct 27, 2006 5:21 pm
by asif_rahman0
Hi technobug,
i think you program doesn't give correct output for the following input:

Code: Select all

22225
225
check it out.
bye

Posted: Sun Oct 29, 2006 5:44 pm
by Raiyan Kamal
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.

Posted: Mon Feb 26, 2007 4:39 am
by kunigas
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.

Re: 743 - The MTM Machine

Posted: Tue Feb 01, 2011 10:59 am
by Imti
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

Re: 743 - The MTM Machine

Posted: Tue Feb 01, 2011 6:24 pm
by helloneo
Input:

Code: Select all

323289
22225
232323
0001
0
My AC code returns

Code: Select all

328923289
2225
32323
NOT ACCEPTABLE

Re: 743 - The MTM Machine

Posted: Thu Feb 03, 2011 9:51 am
by Imti
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

Re: 743 - The MTM Machine

Posted: Fri Feb 04, 2011 4:01 pm
by helloneo
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