UVa : 11660 (Look-and-Say sequences)



// http://uva.onlinejudge.org/external/116/11660.html
// Runtime: 1.408s
// Tag: Adhoc, Simulation

// @BEGIN_OF_SOURCE_CODE

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <cmath>
#include <bitset>
#include <utility>
#include <set>
#include <numeric>

#define INF_MAX 2147483647
#define INF_MIN -2147483647
#define pi acos(-1.0)
#define N 1000000
#define LL long long

#define For(i, a, b) for( int i = (a); i < (b); i++ )
#define Fors(i, sz) for( size_t i = 0; i < sz.size (); i++ )
#define Fore(it, x) for(typeof (x.begin()) it = x.begin(); it != x.end (); it++)
#define Set(a, s) memset(a, s, sizeof (a))
#define Read(r) freopen(r, "r", stdin)
#define Write(w) freopen(w, "w", stdout)

using namespace std;

string str [1000 + 10];

int main ()
{
    int a, b;

    while ( cin >> str [0] >> a >> b ) {
        if ( str [0] == "0" && a == 0 && b == 0 ) break;

        str [0] += '-';
		char num [1000];

        for ( int i = 1; i < a; i++ ) {
            int cnt = 1;
			str [i] = "";
			for (int j = 0; j < str [i - 1].size () - 1 && j <= 1000; j++ ) {
                if ( str [i - 1] [j] == str [i - 1] [j + 1] ) cnt++;
                else {
					sprintf (num, "%d", cnt);
                    str [i] += num;
					//cout << str [i] << endl;
					str [i] += str [i - 1].at (j);
					//cout << str [i] << endl;
                    cnt = 1;
                }
				//cout << str [i] << endl;
            }
            str [i] += "-";
			//cout << str [i] << endl;
        }

        cout << str [a - 1] [b - 1] << endl;
    }

	return 0;
}

// @END_OF_SOURCE_CODE
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s