---
title: 'UVa 490 題解 — C++'
disqus: hackmd
---
# UVa 490 題解 — C++
:::info
:bulb: 此筆記為UVa 490的題目詳解,包含解題思路、C++範例程式碼。
:::
## Rotating Sentences (ZeroJudge c045.)
### [題目](https://zerojudge.tw/ShowProblem?problemid=c045)
:::success
在這個問題中你必須將數列文字往順時針方向旋轉90度。也就是說將原本由左到右,由上到下的句子輸出成由上到下,由右到左。
:::
### 輸入 / 輸出說明
| **輸入說明** | **輸出說明** |
|:-:|:-:|
|  | |
### 解題思路
:::warning
透過 getline(cin, w[n+1]) 取得輸入字串(若使用 cin >> w[n+1],在遇到空格時會結束輸入)。
利用輸出 w[j][i] 達成行列互換。
⚠️請注意,如果你使用ZeroJudge平台的 測試執行 功能的時候,發現過不了(差在那個. )是正常的,在正式執行時不會有問題。
:::
### 範例程式碼
```C++=
#include <bits/stdc++.h>
using namespace std;
int main ()
{
ios::sync_with_stdio(false);
cin.tie(0);
int i, j, n = -1, l = 0, used = 0;
string w[100];
while (getline(cin, w[n+1])) {
n++;
if (w[n].size() > l)
l = w[n].size();
}
for (i=0;i<l;i++) {
for (j=n;j>=0;j--)
if (w[j].size() >= i + 1)
cout << w[j][i];
else
cout << " ";
cout << endl;
}
return 0;
}
```
### 運行結果
<font color="#00BB00">**AC**</font> (3ms, 348KB)
###### tags: `CPE 1星`
:::danger
查看更多資訊請至:https://www.tseng-school.com/
:::