PAT1048 数字加密 (20 分)
生活随笔
收集整理的這篇文章主要介紹了
PAT1048 数字加密 (20 分)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
題目
易錯(cuò)點(diǎn):如果字符串a(chǎn)>b,要把b前面補(bǔ)0,并且這些0要參與運(yùn)算。但是題目中并沒有說明啊???
代碼
#include<iostream> #include<string> using namespace std; int main() {string strA;string strB;cin >> strA >> strB;int lenA = strA.length();int lenB = strB.length();//放進(jìn)數(shù)組中int a[100] = { 0 };int b[100] = { 0 };int aSize = 0;int bSize = 0;int i;for (i = lenA - 1; i >= 0; i--){a[aSize] = strA[i] - '0';aSize++;}for (i = lenB - 1; i >= 0; i--){b[bSize] = strB[i] - '0';bSize++;}//轉(zhuǎn)換 int j;for (i = 0; i < lenA; i += 2)//奇數(shù) {b[i] = b[i] + a[i];b[i] %= 13;}for (j = 1; j < lenA; j += 2)//偶數(shù) {b[j] -= a[j];if (b[j] < 0){b[j] += 10;}}//輸出for (j = (lenA > lenB ? lenA : lenB) - 1; j >= 0; j--){if (b[j] == 10)cout << 'J';else if (b[j] == 11)cout << 'Q';else if (b[j] == 12)cout << 'K';else cout << b[j];}cout << endl;return 0; }總結(jié)
以上是生活随笔為你收集整理的PAT1048 数字加密 (20 分)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PAT1049 数列的片段和 (20 分
- 下一篇: PAT1056 组合数的和 (15 分)