---
title: 'UVa 272 題解 — C++'
disqus: hackmd
---
# UVa 272 題解 — C++
:::info
:bulb: 此筆記為UVa 272的題目詳解,包含解題思路、C++範例程式碼。
:::
## TeX Quotes (ZeroJudge c007.)
### [題目](https://zerojudge.tw/ShowProblem?problemid=c007)

### 輸入 / 輸出說明
| **輸入說明** | **輸出說明** |
|:-:|:-:|
|  |  |
### 解題思路
:::warning
透過 cin.get(text) 取得輸入字元(若使用 cin >> text 會讀不到空格),當 text = " 時,依以下規則判斷:
1. check = 1 => 輸出 ``
2. check = 0 => 輸出 ''
並利用 check = (check + 1) % 2 將 check 更新(1 改為 0、0 改為 1)
:::
### 範例程式碼
```C++=
#include <iostream>
using namespace std;
int main ()
{
ios::sync_with_stdio(false);
cin.tie(0);
int check = 1;
char text;
while (cin.get(text)) {
if (text == '"') {
if (check == 1)
cout << "``";
else
cout << "''";
check = (check + 1) % 2;
}
else
cout << text;
}
return 0;
}
```
### 運行結果
<font color="#00BB00">**AC**</font> (6ms, 312KB)
###### tags: `CPE 1星`
:::danger
查看更多資訊請至:https://www.tseng-school.com/
:::