• B1048 数字加密


    15/20

    #include<bits/stdc++.h>
    using namespace std;
    stack<int> s;
    char a[3]={'J','Q','K'};
    int main(){
        long long A,B;
        cin>>A>>B;
        int i=1;
        while(A>0&&B>0){
            if(i%2==1){
                s.push((A%10+B%10)%13);
            }else{
                int x=B%10-A%10;
                if(x<0)x+=10;
                s.push(x);
            }
            A/=10;B/=10;
            i++;
        }
        if(A>0)cout<<A;
        if(B>0)cout<<B;
        while(!s.empty()){
            if(s.top()<=9)cout<<s.top();
            else cout<<a[s.top()-10];
            s.pop();
        }
        return 0;
    }
    

    后来觉得题目理解有问题,B的每一位数字都要处理。
    15/20

    #include<bits/stdc++.h>
    using namespace std;
    stack<int> s;
    char a[3]={'J','Q','K'};
    int main(){
        long long A,B;
        cin>>A>>B;
        int i=1;
        while(B>0){
            if(i%2==1){
                s.push((A%10+B%10)%13);
            }else{
                int x=B%10-A%10;
                if(x<0)x+=10;
                s.push(x);
            }
            if(A>0)A/=10;
            B/=10;
            i++;
        }
        while(!s.empty()){
            if(s.top()<=9)cout<<s.top();
            else cout<<a[s.top()-10];
            s.pop();
        }
        return 0;
    }
    

    然而还是不行,看了其他人的博客,发现是因为没考虑这种A比B长的情况。

    真是太奇葩了,明明和题目要求不符了嘛。再改。

    #include<bits/stdc++.h>
    using namespace std;
    stack<int> s;
    char a[3]={'J','Q','K'};
    int main(){
        long long A,B;
        cin>>A>>B;
        int i=1;
        while(B>0||A>0){
            if(i%2==1){
                s.push((A%10+B%10)%13);
            }else{
                int x=B%10-A%10;
                if(x<0)x+=10;
                s.push(x);
            }
            if(A>0)A/=10;
            if(B>0)B/=10;
            i++;
        }
        while(!s.empty()){
            if(s.top()<=9)cout<<s.top();
            else cout<<a[s.top()-10];
            s.pop();
        }
        return 0;
    }
    

    改完了,17/20,还有两个测试点没过。

    keep going
  • 相关阅读:
    Js使用WScript.Shell对象执行.bat文件和cmd命令
    wscript运行js文件
    Linux基础tree命令
    使用libssh2库实现支持密码参数的ssh2客户端
    zlib库剖析(1):实现概览
    Linux设置编译器环境变量
    开源的zip_unzip库
    黑客入门之单机游戏外挂
    linux定时任务的设置 crontab 配置指南
    Linux crontab定时执行任务 命令格式与详细例子
  • 原文地址:https://www.cnblogs.com/MarkKobs-blog/p/10557854.html
Copyright © 2020-2023  润新知