一二三四五 上山打老虎

学习通题目格式批量整理小模拟

因为需要导入大量的题目到学习通中,所以写了个小小的模拟放在这里,以后用到的时候再拿去套用。


需要将上图的格式修改为下图中的类似格式,方便导入到题库

为了防止乱码,最好使用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;
}

posted @ 2021-10-22 22:18  abestxun  阅读(900)  评论(0编辑  收藏  举报