zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    Android composite adb interface
    android自适应屏幕方向和大小
    Android音频介绍
    android如何播放和录制音频
    Android中解决图像解码导致的OOM问题
    android 图片占用内存与什么有关
    int android.graphics.Bitmap.getRowBytes()
    Thymeleaf select 反显 默认选中
    淘宝H5 sign加密算法
    c# 菜鸟包裹查询
  • 原文地址:https://www.cnblogs.com/MarkKobs-blog/p/10557854.html
Copyright © 2011-2022 走看看