743  The MTM Machine
Moderator: Board moderators
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
and the output of course
i'm still confused with the 3rd rule
thanks
peace...
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
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
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?
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,len1);
if(s[0]=='3' && len==1) goto bz;
if(s[0]=='3') {
string z = parse(s.substr(1,len1),len1);
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;
}
Ami ekhono shopno dekhi...
HomePage
HomePage

 Experienced poster
 Posts: 106
 Joined: Thu Jan 29, 2004 12:07 pm
 Location: Bangladesh
 Contact:
I think you have misunderstood something. The problem states...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.
Suppose you haveRule 1:
Given any number X not containing a digit zero, then number 2X produces X. For example, 234 produces 34.
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
Ami ekhono shopno dekhi...
HomePage
HomePage

 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:
check it out.
bye
i think you program doesn't give correct output for the following input:
Code: Select all
22225
225
bye

 Experienced poster
 Posts: 106
 Joined: Thu Jan 29, 2004 12:07 pm
 Location: Bangladesh
 Contact:
Yeah, I think
should output
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.
Code: Select all
2222
Code: Select all
222
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
I'm getting WA.Please verify anyone my output's with accepted code:
Input
Input
Output323289
22225
232323
0001
Code: Select all
89289289289
5
3232323
NOT ACCEPTABLE
Re: 743  The MTM Machine
Input:
My AC code returns
Code: Select all
323289
22225
232323
0001
0
Code: Select all
328923289
2225
32323
NOT ACCEPTABLE
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
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
Well, the example of 33289 is pretty much explained by UFP2161..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
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