Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.9 kB
0
Indexable
Never
#include<iostream>
//#include"function.h"

//#ifndef FUNCTION_H
#define FUNCTION_H
#include <iostream>
using namespace std;

class String_Calculator {
    public:
        String_Calculator(){};
        String_Calculator(const string);
        String_Calculator& Add(const string);
        String_Calculator& Subtract(const string);
        String_Calculator& Shift(const string);
        void output() const;

    private:
        string s = "";
}; //end class String_Calculator

//#endif // FUNCTION_H
string str[38]={"0","0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
long long int become(const string ss){
    long long int num=0,pos=ss.size();
    for(int i=0;i<pos;i++){
        string st=ss.substr(i,1);
        if(st=="1") num=num*10+1;
        else if(st=="2") num=num*10+2;
        else if(st=="3") num=num*10+3;
        else if(st=="4") num=num*10+4;
        else if(st=="5") num=num*10+5;
        else if(st=="6") num=num*10+6;
        else if(st=="7") num=num*10+7;
        else if(st=="8") num=num*10+8;
        else if(st=="9") num=num*10+9;
        else if(st=="0") num=num*10;
        else{
            num=-1;
            break;
        }
    }
    return num;
}

String_Calculator::String_Calculator(const string ss){
    this->s=ss;
}

String_Calculator&String_Calculator::Add(const string ss){
    this->s=this->s+ss;
    return *this;
}

String_Calculator&String_Calculator::Subtract(const string ss){
    int pos=-1;
    pos=this->s.find(ss);
    
    if(pos>-1 && pos<this->s.size()){
        this->s.erase(pos,ss.size());
    }else{
        this->s="error";
    }
    return *this;
}
String_Calculator&String_Calculator::Shift(const string ss){
    long long int a=become(ss),pos=this->s.size();
    if(a==-1){
        this->s="error";
        return *this;
    }
    for(int i=0;i<pos;i++){
        string st=this->s.substr(i,1);
        for(int j=1;j<=36;j++){
            if(st==str[j]){
                st=str[(j+a)%36];
                break;
            }
        }
        if(i==0){
            this->s=st+this->s.substr(i+1,this->s.size()-i-1);
        } else if(i==pos){
            this->s=this->s.substr(0,i)+st;
        } else{
            this->s=this->s.substr(0,i)+st+this->s.substr(i+1,this->s.size()-i-1);
        }
    }
    return *this;
}
void String_Calculator::output() const{
    cout << this->s <<endl;
    return;
}


using namespace std;
int main(){
    int n;
    string x, y, c;
    cin >> n;
    while(n--){
        cin >> x >> y >> c;
        String_Calculator a(x), ans;
        if(c == "+")
            ans = a.Add(y);
        if(c == "-")
            ans = a.Subtract(y);
        if(c == "@")
            ans = a.Shift(y);
        ans.output();
    }
}