## 743 - The MTM Machine

Moderator: Board moderators

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

### 743 - The MTM Machine

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

i'm still confused with the 3rd rule

-thanks-
peace...

UFP2161
A great helper
Posts: 277
Joined: Mon Jul 21, 2003 7:49 pm
Contact:
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:
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
Contact:
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
Contact:
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
Contact:
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
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
Contact:
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.

kunigas
New poster
Posts: 4
Joined: Mon Feb 26, 2007 4:29 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
Contact:

### Re: 743 - The MTM Machine

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

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
Contact:

### Re: 743 - The MTM Machine

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

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