#UVa:445-Marvelous Mazes

灆洢 2012-03-30 23:30:32

解讀輸入的字元代表的是什麼意思,在照意思輸出即可。

P.S. 數字的輸入若有兩位數以上,並不是指其數字值,而是各位數相加的值。

C++(0.008)

/*******************************************************/
/* UVa 445 Marvelous Mazes                             */
/* Author: Maplewing [at] knightzone.studio            */
/* Version: 2012/03/30                                 */
/*******************************************************/
#include<iostream>
#include<cstdio>
#include<cctype>
using namespace std;

int main(){
  char s;
  int times = 0;

  while( ( s = getchar() ) != EOF ){
    if( isdigit(s) )
      times += (int)(s-'0');
    else if( s == '!' )
      printf( "\n" );
    else if( s == 'b' ){
      while( times-- ) printf( " " );
      ++times;
    }
    else if( isgraph(s) ){
      while( times-- ) printf( "%c", s );
      ++times;
    }
    else if( s == '\n' )
      printf( "\n" );
  }
  return 0;
}

發表迴響

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