ACM (TJU) : 2971


#include <iostream>
using namespace std;

int main ()
{
    string m;
    string temp;
    unsigned long n;
    unsigned int i;

    while ( cin >> m >> n ) {

        if ( n / m.length () ) {

            i = 0;
            temp.clear ();

            while ( i < m.length () ) {
                if ( m.at (i) != '0' )
                    temp.push_back (m.at (i));
                i++;
            }

            n -= m.length ();
            m = temp;
        }

        int rotation = n % m.length ();

        while ( rotation-- ) {
            temp.clear ();
            temp += m.at (m.length () - 1);
            i = 0;
            while ( i < m.length () - 1 )
                temp += m.at (i++);
            m = temp;
        }

        i = 0;
        while ( m.at (i) == '0' )
            i++;

        while ( i < m.length () )
            cout << m.at (i++);

        cout << endl;

    }

    return 0;
}
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