TEX Quotes UVa-272

原题点此

题意:即将文本中的左引号 " 替换成 ``,右引号 " 替换成 '',并且文本中不会出现引号嵌套的情况。

思路:用getchar()函数逐个读入,若是引号则替换成题目所要求的的符号,若不是则原样输出。

代码:

#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;

int main()
{
    //freopen("in.txt","r",stdin);
    char c;
    int flag=1;
    while((c=getchar())!=EOF)//一直读到文件尾
    {
        if(flag==1&&c=='"')
        {
            printf("``");
            flag=0;
        }
        else if(flag==0&&c=='"')
        {
            printf("''");
            flag=1;
        }
        else
            printf("%c",c);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/baymax__dabai/article/details/81149271
TEX