题目大意:输入一串字符,对于第一个"号改成``,对于第二次的‘’。
我的代码:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
int main(){
fstream f("file.txt");
vector<string> words;
string line;
while(getline(f,line)){
words.push_back(line);
}
for(int i = 0;i < words.size(); ++i){
int i=1;
for(int j = 0;j < words[i].size()-1;++j){
if(words[i][j] == '"'){
if(i&1){
words[i][j].replace('`');
words[i][j].insert('`');
}
}
}
cout << words[i] << endl;
}
return 0;
}
写的有点复杂,建议参考答案,直接使用输出scanf来转化输出:
// UVa272 Tex Quotes
// Rujia Liu
#include<stdio.h>
int main() {
int c, q = 1;
while((c = getchar()) != EOF) {
if(c == '"') { printf("%s", q ? "``" : "''"); q = !q; }
else printf("%c", c);
}
return 0;
}
学习的点:
1.这里的输入存储c,定义的是int.
2.整数的取反也是0;