CSP模板生成系统

开门见山,直接放一百分代码:

c 复制代码
#include<iostream>
#include<algorithm>
#include<cstring>
#include<bits/stdc++.h>
using namespace std;
const int N = 2e4 + 10;
string a[1010];
unordered_map<string , string> mp;

void check(string &s)
{
    int len = s.size();
    string res = "";
    string z;
    for(int i = 0 ; i < len ; i++)
    {
        if(s[i] == '{' && s[i + 1] == '{')
        {
            int j = i + 3;
            string k="";
            while(s[j] != ' ')
            {
                k += s[j];
                j++;
            }
            if(mp.count(k) == 0){
                i = j + 2;
                continue;
            }
            z = mp[k];
            i = j + 2;
            res += z;
            continue;
        }
        res += s[i];
    }
    s = res;
}

int main()
{
    int m , n;
    cin >> m >> n;
    getchar();
    for(int i = 1 ; i <= m ; i++)
    {
        getline(cin , a[i]);
    }
    for(int i = 1 ; i <= n ; i++){
        string k;
        string z;
        cin >> k;
        getline(cin , z);
        string zz="";
        for(int j = 2 ; j < z.size()-1 ; j++)
            zz += z[j];
        mp[k] = zz; 
    }
    for(int i = 1 ; i <= m ; i++)
    {
        check(a[i]);
        cout << a[i] << endl;
    }
    return 0;
}
相关推荐
2401_884602271 小时前
程序人生-Hello’s P2P
c语言·c++
weixin_458872611 小时前
东华复试OJ二刷复盘2
算法
Charlie_lll2 小时前
力扣解题-637. 二叉树的层平均值
算法·leetcode
初中就开始混世的大魔王2 小时前
2 Fast DDS Library概述
c++·中间件·信息与通信
MediaTea2 小时前
Python:collections.Counter 常用函数及应用
开发语言·python
爱淋雨的男人2 小时前
自动驾驶感知相关算法
人工智能·算法·自动驾驶
wen__xvn2 小时前
模拟题刷题3
java·数据结构·算法
LawrenceLan2 小时前
37.Flutter 零基础入门(三十七):SnackBar 与提示信息 —— 页面反馈与用户交互必学
开发语言·前端·flutter·dart