CODR - LOGIC Editorial or Solution SPOJ - UCS - Unleash-Coding-Skills

Thursday, 6 September 2018

CODR - LOGIC Editorial or Solution SPOJ - UCS


CODR - LOGIC

The link to the problem CODR - LOGIC  riddle problem is:

https://www.spoj.com/problems/CODR/

The problem is riddle which stimulate your thinking skills.

Notes:
1) The first important thing is the input ends when n=0.
2)Consider the example of the test case given the problem.
Input:
124

Output:

0208100
Consider the output is divide as follows

02 08 100
a0 a1  a2

and input as

1   2    4
b0 b1 b2

The output is obtained by:

a0 = b0 * b1;
a1 = b1 * b2;

. . . . . .
Be careful while printing the output if it a0 or a1 is a single digit then append "0" while printing like
(e.g.: 02).


Now here comes the twist most of coders leaving the question without solving the question as it is a wrong question with wrong test cases but it is not  :) .

Now we need to use the a0 and a1 we need to subdivide the digits to get the logic.From above test case we have taken as per logic going.

  a0                             a1
 0   2                        0    8
p0  p1                     p2   p3

From above division of a0,a1,a2 we now going to a2.
       a2
  1  0     0
   q1     q2

q1 = p1 + p3

q2 = reverse(p0+p2)

So a2 = append(q1,q2)

So we now got the a0 a1 a2 so we can print the output for the testcase. Similarly, for other test cases.

The CPP solution for  CODR - LOGIC:

#include <iostream>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;
int reverses(int n1)
{
    int r,c=0,sum=0;
    while(n1>0)
    {
        r=n1%10;
        n1=n1/10;
        sum = sum*10+r;
    }
    return sum;
}
int main()
{
int n;
cin>>n;
while(n!=0)
{
int a0,a1,a2;
a2 = n%10;
n= n/10;
a1 = n%10;
n= n/10;
a0 = n;
string an0,an1;
int b;
a0=a0*a1;
if(a0/10==0)
{
cout<<"0"<<a0;
}
else
cout<<a0;
a1= a1*a2;
if(a1/10==0)
cout<<"0"<<a1;
else 
cout<<a1;
int l1,l2,l3,l4,l5,l6;
l1=a0/10;
l2=a0%10;
l3=a1/10;
l4=a1%10;
l5=l1+l3;
l6=l2+l4;
string se1,se2;
se1=to_string(l5);
se2=to_string(l6);
reverse(se1.begin(),se1.end());
cout<<se2<<se1<<endl;
cin>>n;
}
return 0;
}

Happy Coding......

Tags:

CODR - LOGIC Editorial or Solution SPOJ, CODR spoj , code spoj , logic spoj, code solution spoj,
CODR - LOGIC  riddle solution , spoj solution , CODR spoj editorial , code - logic riddle.


1 comment:

  1. Thanks for sharing this information Freyr Energy was founded on the principles of making solar energy affordable and accessible for everyone. In order to make adoption of solar energy a reality at the grass-root level, we have identified that consumer awareness, affordability and accessibility play an integral role. With our innovative platform, SunPro+, our extensive channel-partner network and our efficient service we ensure that these three factors are addressed to make sure your venture into solar energy is hassle-free. Best solar company in Hyderabad-freyr

    ReplyDelete