# UVa 272 - TEX Quotes --- ## 題目大意 給一堆字串,對每組" "將第一個"改成\`\`,第二個改成''輸出。 --- ## 題解 直接遍歷字串,每次看到"便判斷是第一個還是第二個並輸出相應的要求。 小技巧:可以開一個變數為0或1,每次看到"便做一次位元運算的XOR即可輕鬆判斷當前"的要求。 --- ````=C++ #include <bits/stdc++.h> #define ll long long #define pb push_back #define INF 2147483647 #define ft first #define sec second #define pr pair<int,int> #define ISCC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); using namespace std; int t ,n ,m ,k ,a ,cnt; string s; int main() { int ok=1; while(getline(cin,s)) { for(int i=0 ;i<s.size() ;i++) { if(s[i]=='"') { if(ok) cout<<"``"; else cout<<"''"; ok^=1; } else cout<<s[i]; } cout<<'\n'; } } ````
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up