UVa 490 Rotating Sentences

解題策略

相當有趣的題目,要旋轉字串90度再印出。注意字串不足的部份要自行補白。
提供一個測資:
aaa    aaa
 bbb  bbb
  cccccc
   dddd
    ee
   f  f
  g    g
   h  h

/**
* UVa 490 Rotating Sentences
* Author: chchwy
* Last modified: 2010.04.23
*/
#include<iostream>
#include<vector>
using namespace std;
//find the max length of strings
int findMaxX(vector<string>& str)
{
int max = 0;
for (int i = 0; i < str.size(); ++i)
if (str[i].size() > max)
max = str[i].size();
return max;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("490.in", "r", stdin);
#endif
vector<string> str;
//read input
string line;
while ( getline(cin, line) )
str.push_back(line);
//find the bound
int max_y = str.size();
int max_x = findMaxX(str);
//output
for (int i = 0; i < max_x; ++i)
{
for (int j = max_y - 1; j >= 0; --j)
{
char c = (i < str[j].size()) ? str[j][i] : ' ';
putchar(c);
}
putchar('\n');
}
return 0;
}
view raw 490.cpp hosted with ❤ by GitHub

留言

  1. 學長 !!
    你上面那槓也太酷了 !!

    話說我好久沒寫題目了說(慚愧...)

    回覆刪除

張貼留言

這個網誌中的熱門文章

UVa 10125 Sumsets

讀書心得: 撒哈拉的故事

讀書心得: 你以為你以為的就是你以為的嗎?