20220312完美世界笔试

1

// 可以引入的库和版本相关请参考 “环境说明”
#include <iostream>
#include <unordered_map>
#include <string>

using namespace std;



string solution(string str) {
    string res = "";   if(str.empty()) return res;

    unordered_map<string, int> fmp;
    int pre = -1;
    int cnt = 0;
    for(int cur= 0; cur < str.size(); cur++){
        string tmp = str.substr(pre + 1, cur - pre);
        //出现过
        if(fmp.find(tmp) != fmp.end()){
            if(cur == str.size() - 1) res += to_string(fmp[tmp]);
            else continue;
        }
            //没出现过
        else{
            fmp.insert({tmp, ++cnt});
            // 单个字符
            if(tmp.size() == 1) res.push_back('0');
                // 多个字符
            else {tmp.pop_back(); res += to_string(fmp[tmp]);}

            res.push_back(str[cur]);

            pre = cur;
        }

    }
    return res;
}




int main(){
    cout << solution("ABBCBCABABCAABCAAB") << endl;
    cout << solution("AAAAAAAAA") << endl;
}

2

#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

const int N = 10010;
int mx, my, n;
int a[N], b[N], c[N], d[N];
int lx[N], ly[N];
int idx;

int main(){
    scanf("%d %d", &mx, &my);
    scanf("%d", &n);
    while(n -- ){
        scanf("%d %d", &lx[idx], &ly[idx]);
        idx++;
    }

    int mv, tx, ty; scanf("%d %d %d", &mv, &tx, &ty);
    mv --;


    //(a,b)
    //     (c, d)

    int s = 0;
    for(int i=0; i<idx; i++){
        a[i] = s;
        s += lx[i];
        c[i] = s;
    }
    memset(b, 0, sizeof b);
    for(int i=0; i<idx; i++) d[i] = ly[i];


    int gx = tx - a[mv], gy = ty - b[mv];

    // 移动
    for(int i=0; i<idx; i++){
        a[i] += gx, b[i] += gy,
        c[i] += gx, d[i] += gy;
    }

    int dx = 0, dy = 0;
    if(a[0] < 0) dx -= a[0];
    if(c[idx] > mx) dx = (mx - c[idx]);
    if(b[0] < 0) dy -= b[0];

    for(int i=0; i<idx; i++){
        if(d[i] > my){
            int ny = my - d[i];
            if(ny < dy) dy = ny;
        }
    }

    for(int i=0; i<idx; i++){
        a[i] += dx, b[i] += dy;
    }

    for(int i=0; i<idx; i++){
        printf("%d %d\n", a[i], b[i]);
    }
}

/*
 *

100 100
2
50 50
40 60
2 0 0

 */
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ColaForced

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值