1. 程式人生 > >UVA272--TEX Quotes【字串】

UVA272--TEX Quotes【字串】

TEX Quotes

題目傳送門

題目大意:將輸入字串中的所有對雙引號的做雙引號改為 `` ,右雙引號改為 '' 。

解決方法:遍歷一遍及時修改即可。

AC程式碼:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <set>
#include <utility>
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define lep(i,l,r) for(int i=l;i>=r;i--)
#define ms(arr) memset(arr,0,sizeof(arr))
//priority_queue<int,vector<int> ,greater<int> >q;
const int maxn = (int)1e5 + 5;
const ll mod = 1e9+7;
int main() 
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(0),cin.tie(0);
    int c;
    int ju=1;    //判斷是否是第一次出現
    while((c=getchar())!=EOF)
    {
    	if(c==(int)'"')
    	{
    		if(ju)
    		{
    			printf("``");
    			ju=0;
    		}
    		else
    		{
    			printf("''");
    			ju=1;
    		}

    	}
    	else
    		printf("%c",c);
    }

    return 0;
}