例题3-1 UVA 272 TEX Quotes

我还搞了string,什么流输入输出储存,花里胡哨的也没啥大用,汝佳大佬一个getchar就解决了,数据存都不用存。

大佬写的。

#include <bits/stdc++.h>
using namespace std;

int main()  {
    int c,q=1;
    while ((c=getchar())!=EOF)    {
        if (c=='"') {
            printf("%s",q?"``":"''");
            q=!q;
        }
        else    printf("%c",c);
    }
    return 0;
}

我写的

#include <bits/stdc++.h>
using namespace std;

int main()  {
    string s;
    bool p=true;
    while (getline(cin,s))  {
        for (unsigned i=0;i<s.size();i++) {
            if (s[i]=='"'){
                if (p)  cout<<"``";
                else    cout<<"''";
                p=!p;
            }
            else    cout<<s[i];
        }
        cout<<endl;
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/yichuan-sun/p/9628519.html