在TeX中,做雙引號是``,右雙引號是‘‘,輸入一篇包含雙引號的文章,你的任務是把它轉換成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''.
本題的關鍵是如何判斷一個班雙引號是”左“雙引號還是“右”雙引號,方法是使用一個標誌量即可
我是這麼寫的
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
int c;
bool flag=true;
while((c=getchar())!=EOF){
if(flag&&c=='"'){
printf("``");
flag=false;
continue;
}
if(!flag&&c=='"'){
printf("''");
flag=true;
continue;
}
putchar(c);
}
return 0;
}
書上寫的簡短點,不過思想都是一樣的,設計一個標誌量
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
int c;
int p=1;
while((c=getchar())!=EOF)
{
if(c=='"'){
printf("%s",p ? "``" : "''");
p=!p;
}
else putchar(c);
}
return 0;
}