#UVa:490-Rotating Sentences

先將輸入存進二維陣列中,再用題目所要求的順序輸出答案。

C++(0.015)

/*******************************************************/
/* UVa 490 Rotating Sentences                          */
/* Author: LanyiKnight [at] knightzone.org             */
/* Version: 2014/12/29                                 */
/*******************************************************/
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main(){
  const int MAX_LENGTH = 100;
  char sentences[MAX_LENGTH+5][MAX_LENGTH+5] = {0};

  int rowLimit = 0, colLimit = 0;
  while( gets(sentences[rowLimit]) ){
    colLimit = max( colLimit, (int)strlen(sentences[rowLimit]) );
    ++rowLimit;
  }

  for( int i = 0 ; i < colLimit ; ++i ){
    for( int j = rowLimit-1 ; j >= 0 ; --j ){
      if( sentences[j][i] == 0 ){
        printf(" ");
        continue;
      }
      printf("%c", sentences[j][i]);
    }
    printf("\n");
  }

  return 0;
}

沒有迴響

本文還沒有迴響,快來搶頭香!

發表迴響