#UVa:10361-Automatic Poetry

灆洢 2016-04-20 08:28:01

照著所要求的方式去拆解字串再組合起來即可得解。

C++(0.000)

/*******************************************************/
/* UVa 10361 Automatic Poetry                          */
/* Author: Maplewing [at] knightzone.studio            */
/* Version: 2016/04/20                                 */
/*******************************************************/
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;

int main(){
  int n;
  while( scanf("%d", &n) != EOF ){
    getchar();

    for( int caseNumber = 0 ; caseNumber < n ; ++caseNumber ){
      string s[5];
      for( int i = 0 ; i < 5 ; ++i ){
        char c;
        while( (c = getchar()) && c != '<' && c != '>' && c != '\n' ){
          s[i] += c;
        }
      }

      for( int i = 0 ; i < 5 ; ++i ){
        printf("%s", s[i].c_str());
      }
      printf("\n");

      string c2;
      getline(cin, c2);
      c2 = c2.substr(0, c2.length() - 3) + s[3] + s[2] + s[1] + s[4];
      printf("%s\n", c2.c_str());
    }
  }

  return 0;
}

發表迴響

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