|
发表于 2018-12-7 13:05:21
|
显示全部楼层
- #include <iostream>
- #include <string>
- const std::string Encrypting(const std::string &s_num)
- {
- std::string result;
- for(const auto &i: s_num)
- {
- size_t num = i - '0';
- result += ((num + 7) % 10) + '0';
- }
- std::swap(result[0], result[2]);
- std::swap(result[1], result[3]);
- return result;
- }
- const std::string Decrypting(const std::string &s_num)
- {
- std::string result;
- for(const auto &i : s_num)
- {
- size_t num = i - '0';
- if(num >= 7)
- result += (char(num) - 7) + '0';
- else
- result += (char(num) + 10 - 7) + '0';
- }
- std::swap(result[0], result[2]);
- std::swap(result[1], result[3]);
- return result;
- }
- int main()
- {
- std::string code;
- bool flag;
- std::cin >> code >> flag;
- if(flag)
- {
- std::cout << "After encrypting the number is " << Encrypting(code) << std::endl;
- }
- else
- {
- std::cout << "After decrypting the number is " << Decrypting(code) << std::endl;
- }
- return 0;
- }
复制代码 |
|