因為需要導入大量的題目到學習通中,所以寫了個小小的模擬放在這里,以后用到的時候再拿去套用。
需要將上圖的格式修改為下圖中的類似格式,方便導入到題庫
為了防止亂碼,最好使用UTF-8的編碼,推薦VSCode編碼防止亂碼,對於中文左括號判斷的問題,目前沒有更好的解決方案,索性用txt的替換為英文括號后處理,哈哈哈
代碼:將需要修改格式的文件放到同目錄下problems.txt文檔中。
#include<bits/stdc++.h>
using namespace std;
int main (){
freopen("problems.txt","r",stdin);
freopen("out.txt","w",stdout);
string str;
char c;
int num=0;
while(getline(cin,str)){
if(str[0]>='0'&&str[0]<='9'){
if(num){
printf("答案:%c\n",c);
}
int t=0;
while(str[t]>='0'&&str[t]<='9')t++;
num++;
printf("%d.",num);
for(int i=t;i<(int)str.size();i++){
if(str[i]=='('&&(str[i+1]>='A'&&str[i+1]<='E')){
printf("( ");
c=str[i+1];
i+=2;
}
printf("%c",str[i]);
}
printf("\n");
}
else if(str[0]=='A'||str[0]=='B'||str[0]=='C'||str[0]=='D'){
cout<<str<<endl;
}
}
if(num){
printf("答案:%c\n",c);
}
return 0;
}