#UVa:11687-Digits

灆洢 2012-09-27 23:24:39

照題目要求去算即可得解。

C++(0.056)

/*******************************************************/
/* UVa 11687 Digits                                    */
/* Author: Maplewing [at] knightzone.studio            */
/* Version: 2012/09/27                                 */
/*******************************************************/
#include<iostream>
#include<cstdio>
using namespace std;

int main(){
  string x, last_x, tempstr;
  int n, temp;
  while( getline( cin, x ) ){
    if( x == "END" ) break;
    n = 0;
    do{
      n++;
      last_x = x;
      temp = x.length();
      x = "";
      while( temp ){
        tempstr = (char)((temp%10)+(int)'0');
        tempstr += x;
        x = tempstr;
        temp /= 10;
      }
    }while( last_x != x );
    printf( "%d\n", n );
  }
  return 0;
}

發表迴響

這個網站採用 Akismet 服務減少垃圾留言。進一步瞭解 Akismet 如何處理網站訪客的留言資料