PAT 乙级 1048 数字加密 (20 分)
2019-08-15 22:35
113 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/m0_38088647/article/details/99659691
题目:https://pintia.cn/problem-sets/994805260223102976/problems/994805276438282240
经验总结:
注意A和B的中较短的字符串需要在其之前补0,补到两字符串长度相等。可以真的补0,也可以假装补0,例如如下代码为假装补0.
记:reverse_iterator 中的rbegin 到rend 是++而不是–。
C++代码:
#include <iostream> #include <stack> using namespace std; char c[13]={'0','1','2','3','4','5','6','7','8','9','J','Q','K'}; int main(){ string a,b; cin>>a>>b; stack<char> result; int i = 1; string::reverse_iterator it1 = a.rbegin(),it2 = b.rbegin(); for(;it1!=a.rend()&&it2!=b.rend();it1++,it2++,i++){ int bnum = *it2-'0'; int anum = *it1-'0'; if(i%2==0){ result.push(c[(bnum-anum+10)%10]); }else{ result.push(c[(anum+bnum)%13]); } } while(it1!=a.rend()){ if(i%2==0){ result.push(c[('0'-*it1+10)%10]); }else{ result.push(*it1); } i++; it1++; } while(it2!=b.rend()){ result.push(*it2); it2++; } while(!result.empty()){ cout<<result.top(); result.pop(); } return 0; }
相关文章推荐
- PAT 乙级 1048. 数字加密(20) Java版
- PAT乙级1048(C语言)-数字加密(20)
- 1048. 数字加密(20)PAT乙级
- PAT 乙级 1048. 数字加密(20)
- PAT乙级 1048. 数字加密(20)
- PAT乙级1048. 数字加密(20)
- PAT乙级 1048. 数字加密(20)
- PAT-乙级-1048. 数字加密(20)
- [PAT乙级]1048. 数字加密(20)
- pat乙级1048. 数字加密(20)
- 1048. 数字加密(20)-浙大PAT乙级真题
- 乙级 PAT 1048. 数字加密(20)
- pat 乙级 1048. 数字加密(20)
- PAT 乙级 1048. 数字加密(20)
- 1048. 数字加密(20)-浙大PAT乙级真题java实现
- 1048. 数字加密(20) PAT乙级真题
- PAT乙级—1048. 数字加密(20)-native
- PAT乙级.1048. 数字加密(20)
- PAT乙级 1048. 数字加密(20)
- PAT(basic level) 1048 数字加密(20)