UVa : 11687 (Digits)

// http://uva.onlinejudge.org/external/116/11687.html


#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>
#define pi acos(-1.0)
#define N 1000000
using namespace std;

char input [1000000 + 10];
int cnt;

int recursive (int x0)
    sprintf (input, "%d", x0);
    int x1 = strlen (input);
    if ( x1 == x0 ) return cnt;
    recursive( x1 );

int main ()
    while ( gets (input) && strcmp (input, "END") ) {
        if ( strcmp (input, "1") == 0 ) {
            printf ("1\n");
        cnt = 1;
        printf ("%d\n", recursive (strlen (input)));

    return 0;


One thought on “UVa : 11687 (Digits)

  1. Since x0 and x1 are both local to the recursive() function, shouldn’t the last line of that function have to be “return(recursive(x1));” rather than simply “recursive(x1);” ?

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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s