竹園論壇

標題: Q272 - TeX Quotes [打印本頁]

作者: HSCHE    時間: 2014-4-28 14:55
標題: Q272 - TeX Quotes
本帖最後由 HSCHE 於 2014-4-29 08:04 編輯

TeX 是一種由 Donald Knuth 所發展出的一套文書排版軟體。這套軟體可以將原始文件檔加上一些像字型等型態後,轉成一份很漂亮的文件。而一份漂亮的文件是需要用 `` 和 " 來把別人說的話給「引」出來,而不是用大部份鍵盤上有的 " 。雖然鍵盤裡通常不會有這種有方向的雙引號鍵,不過上面有左單引號 ` (有人叫 backquote ),和右單引號 ' (有人叫 apostrophe 或 quote )。你可以在你的鍵盤上找一下,不過要小心不要將 ` 與 \ ( backslash 鍵)搞混了。而在 TeX 裡,使用者可以輸入兩個左單引號 `` 來構成一個左雙引號 `` ,或者是兩個右單引號 '' 來構造一個右單引號 '' ,不過呢,通常大家打字時都很習慣用普通的雙引號 " 來引述別人的話。
如果原始文件檔內容是:
"To be or not to be," quoth the bard, "that is the question."
則 TeX 作出來的文件並不會是我們所想要的:
``To be or not to be," quoth the bard, ``that is the question."
為了要得到上面的文件,我們需要把原始文件變成這個樣子:
``To be or not to be,'' quoth the bard, ``that is the question.''
你現在必須要寫一個程式,將普通的雙引號("),轉成有方向性的雙引號,而其它文字則不變。而在把普通的雙引號換掉的時候,要特別注意,當要開始引述一句話時要用 `` ,而結束引述時要用 '' 。不用擔心會有多層巢狀引號的情形,也就是第一個引號一定是用 `` 來代替,再來用 '',然後用 `` ,接著用 '' ,依此類推。
Input and Output
輸入是若干列的文字,其中有偶數個雙引號( " ),以 end-of-file 做結束。輸出的文字必須和輸入的一模一樣,除了:
Sample Input
"To be or not to be," quoth the Bard, "thatis the question".The programming contestant replied: "I must disagree.To `C' or not to `C', that is The Question!"
Sample Output
``To be or not to be,'' quoth the Bard, ``thatis the question''.The programming contestant replied: ``I must disagree.To `C' or not to `C', that is The Question!''

在此附上題目連結UVA:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=208LUCKY CAT:http://luckycat.kshs.kh.edu.tw/homework/q272.htm解題感想:這題主要是讀入的問題,只要成功讀入之後,輸出便不是問題,切記要換行!!

AC CODE:
#include<iostream>
  • #include<cstdio>
  • #include<cstring>
  • using namespace std;
  • int main()
  • {
  •         int ans=0;
  •         char a[10000];
  •         while(gets(a))
  •         {
  •                 int T=0;
  •                 while(a[T])
  •                 {
  •                         if(a[T]=='\"')
  •                         {        
  •                                 ans++;
  •                                 if(ans%2==1)
  •                                 {
  •                                         cout<<"``";
  •                                 }
  •                                 if(ans%2==0)
  •                                 {
  •                                         cout<<"''";
  •                                 }
  •                         }
  •                         else
  •                                 cout<<a[T];
  •                                 
  •                         T++;
  •                 }
  •                 cout<<"\n";
  •         }
  • }







  • 歡迎光臨 竹園論壇 (http://forum.tfcis.org/) Powered by Discuz! X3.2