小楷来救一救

#include <iostream>
#include <vector>
using namespace std;
class Sulotion {
  public:
    vector<pair<string, int>> ping = {{"abc", 2}, {"def", 3}, {"ghi", 4}, {"jkl", 5},
        {"mno", 6}, {"pqrs", 7}, {"tuv", 8}, {"wxyz", 9}
    };
    string deCode(string& code) {
        int size = code.size();
        string res = "";
        for (int i = 0; i < size; i++) {
            if (code[i] >= '0' && code[i] <= '9') {
                res += code[i];
            } else if (code[i] >= 'a' && code[i] <= 'z') {
                for (int j = 2; j < 10; j++) {
                    if (ping[j - 2].first.find(code[i]) != string::npos) {
                        res += to_string(j);
                    }
                }
            } else if (code[i] >= 'A' && code[i] < 'Z') {
                char c = tolower(code[i]);
                res += (c - 'a' + 1) % 26 + 'a';
            } else if (code[i] == 'Z') {
                res += 'a';
            }
        }
        return res;
    }
};

int main() {
    string line;
    getline(cin, line);
    Sulotion A;
    cout << A.deCode(line) << endl;
    return 0;
}

第二个

#include <bits/stdc++.h>
using namespace std;

class My_vector {
  public:
    My_vector() {};
    My_vector(char s, int num) {
        switch (s) {
            case 'A':
                x = -1;
                break;
            case 'D':
                x = 1;
                break;
            case 'W':
                y = 1;
                break;
            case 'S':
                y = -1;
                break;
            default:
                x = 0, y = 0;
                break;
        }
        if (0 < num < 100) {
            x *= num;
            y *= num;
        } else {
            x = 0;
            y = 0;
        }

    }
    My_vector operator+(const My_vector&
                        b) { //类内重载,运算符重载函数作为类的成员函数
        My_vector ret;
        ret.x = this->x + b.x;
        ret.y = this->y + b.y;
        return ret;
    }
    int x = 0, y = 0;
};

void split(string str, vector<string>& res) {
    char* str_ch = str.data();
    char* p = strtok(str_ch, ";");
    while (p != NULL) {
        string tem(p);
        // cout<<tem<<" ";
        res.push_back(tem);
        p = strtok(NULL, ";");
    }

}

int main() {
    string str;
    vector<string> res;
    My_vector ans;
    stringstream ss;
    while (getline(cin, str)) {
        split(str, res);
        for (int i = 0; i < res.size(); i++) {

            string tem = res[i];
            int tem_int;
            if (tem.size() == 1 || tem.size() > 3 || tem[1] > 61 || tem[2] > 61)
                continue;
            tem_int = std::stoi(tem.substr(1));
            //cout <<tem_int<<" ";
            My_vector temp(tem[0], tem_int);
            ans = ans + temp;
        }
    }

    cout << ans.x << "," << ans.y;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值