Sunday 19 October 2014

Nekops-Nu Sequences

A Nekops-Nu sequence is computed from any sequence of integers by following these rules starting from the first number (left-most number) in the sequence:
Count the number of successive repetitions of the same number.
Output the count and then the number.
Repeat steps 1-3 for the next digit in the sequence
For example, given the sequence “1 2 1 1”, the Nekops-Nu sequence can be computed as:
There is 1 instance of the number 1.
There is 1 instance of the number 2.
There are 2 instances of the number 1.
The new Nekops-Nu sequence is “1 1 1 2 2 1”
The same set of rules can be applied to the resulting sequence to generate more patterns. See the sample
output for further continuations to the example provided.
Task
Write a program that computes the next K instances of the Nekops-Nu sequence for a given sequence of
numbers.
Input
The input will contain:
0 <= Number of iterative sequences to compute, K <= 10
Initial sequence of 1 <= N <= 250
The numbers in the sequence can have any valid 32-bit integer value.
Outpu The output contains one Nekops-Nu sequence per line starting with the initial input sequence and followed by the K sequences computed. The numbers in each sequence are separated by a single space character. To make the output look more interesting, add periods to pad all the sequences (before and after) such that they are centered align with respect to the longest sequence computed. Given the example above, the two sequences were “1 2 1 1” (length 7 characters) and “1 1 1 2 2 1” (length 11 characters). Therefore the output
should show:
..1 2 1 1..
1 1 1 2 2 1
If a specific row and the longest row do not line up (because of odd and even numbers of characters), then
add an extra dot before the sequence as shown in input/output #2, or refer to the following example:
.....9999 9999....
......2 9999......
....1 2 1 9999....
1 1 1 2 1 1 1 9999
(i.e. if the number of characters is even in a specific row, then there should be an extra dot before the
sequence)
Finally, on the last line, output the number of elements found in the last sequence.
Note: There is a newline character at the end of the last line of the output.
Sample Input 1
3 1 2 1 1
Sample Output 1
....1 2 1 1....
..1 1 1 2 2 1..
..3 1 2 2 1 1..
1 3 1 1 2 2 2 1
8
Sample Input 2
1 1 1 1 1 1 1 1 1 1 1
Sample Output 2
1 1 1 1 1 1 1 1 1 1
........10 1.......
2

/* Coding */


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    // input stream of number
    long int number;
    int limit,new_number,i
    int first_number, next_number;
    int count=0;
    cin>>number;
    //predicting how long the number is...
    if( number > 10 && number < 100 )
        {
        limit=number/10;
        new_number=number%10;
        }
    if( number > 100 && number < 1000 )
        {
        limit=number/100;
        new_number=number%100;
        }
    if( number > 1000 && number < 10000 )
        {
        limit=number/1000;
        new_number=number%1000;
        }
     if( number > 10000 && number < 100000 )
        {
        limit=number/10000;
        new_number=number%10000;
        }
     if( number > 100000 && number < 1000000 )
        {
        limit=number/100000;
        new_number=number%100000;
        }
    // limit. control. loop
   
    for(i=0;i<3;i++)
        {
        if( i=0 )
            {
            cout<<"....";
        }
        if( i=1 )
            {
            cout<<"...";
            }
        if( i=2 )
            {
            cout<<"..";
        }
       
        if( new_number > 0 && new_number < 10 )
            {
            first_number=new_number;
            cout<<"1"<<first_number;
            count = count + 2;
        }
        if(new_number > 10 && new_number < 100 )
            {
            first_number=new_number/10;
            //new_number=new_number%10;
            next_number=new_number%10;
            if ( first_number == next_number )
                {
                cout<<"2"<<first_number;
                count = count + 3;
            }
            else
                {
                cout<<"1"<<first_number;
                cout<<"1"<<next_number;
                count = count + 4;
            }
        }
        if(new_number > 100 && new_number < 1000 )
            {
            first_number=new_number/100;
            new_number=new_number%100;
            next_number=new_number/10;
            if ( first_number == next_number )
                {
                cout<<"2"<<first_number;
                count = count + 3;
            }
            else
                {
                cout<<"1"<<first_number;
                cout<<"1"<<next_number;
                count = count + 4;
            }
        }
        if(new_number > 1000 && new_number < 10000 )
            {
            first_number=new_number/1000;
            new_number=new_number%1000;
            next_number=new_number/100;
            if ( first_number == next_number )
                {
                cout<<"2"<<first_number;
                count = count + 3;
            }
            else
                {
                cout<<"1"<<first_number;
                cout<<"1"<<next_number;
                count = count + 4;
            }
        } 
        if(new_number > 10000 && new_number < 100000 )
            {
            first_number=new_number/10000;
            new_number=new_number%10000;
            next_number=new_number/1000;
            if ( first_number == next_number )
                {
                cout<<"2"<<first_number;
                count = count + 3;
            }
            else
                {
                cout<<"1"<<first_number;
                cout<<"1"<<next_number;
                count = count + 4;
            }
        }
        if(new_number > 100000 && new_number < 1000000 )
            {
            first_number=new_number/100000;
            new_number=new_number%100000;
            next_number=new_number/10000;
            if ( first_number == next_number )
                {
                cout<<"2"<<first_number;
                count = count + 3;
            }
            else
                {
                cout<<"1"<<first_number;
                cout<<"1"<<next_number;
                count = count + 4;
            }
        }
        if(i=0)
            {
            cout<<"...."<<endl;
        }
        if(i=1)
            {
            cout<<"..."<<endl;
        }
        if(i=2)
            {
            cout<<".."<<endl;
        }
       
    }
    cout<<count;
      return 0;
}