UVa 490 Rotating Sentences
解題策略
相當有趣的題目,要旋轉字串90度再印出。注意字串不足的部份要自行補白。提供一個測資:
aaa aaa bbb bbb cccccc dddd ee f f g g h h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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; | |
} | |
學長 !!
回覆刪除你上面那槓也太酷了 !!
話說我好久沒寫題目了說(慚愧...)
簡單有趣
回覆刪除