鱼C论坛

 找回密码
 立即注册
查看: 4875|回复: 7

oj显示答案错误,检查了半天没发现错误

[复制链接]
发表于 2018-12-7 13:05:21 | 显示全部楼层
  1. #include <iostream>
  2. #include <string>

  3. const std::string Encrypting(const std::string &s_num)
  4. {
  5.         std::string result;
  6.         for(const auto &i: s_num)
  7.         {
  8.                 size_t num = i - '0';
  9.                 result += ((num + 7) % 10) + '0';
  10.         }

  11.         std::swap(result[0], result[2]);
  12.         std::swap(result[1], result[3]);
  13.         return result;
  14. }

  15. const std::string Decrypting(const std::string &s_num)
  16. {
  17.         std::string result;
  18.         for(const auto &i : s_num)
  19.         {
  20.                 size_t num = i - '0';
  21.                 if(num >= 7)
  22.                         result += (char(num) - 7) + '0';
  23.                 else
  24.                         result += (char(num) + 10 - 7) + '0';
  25.         }

  26.         std::swap(result[0], result[2]);
  27.         std::swap(result[1], result[3]);
  28.         return result;
  29. }

  30. int main()
  31. {
  32.         std::string code;
  33.         bool flag;
  34.         std::cin >> code >> flag;

  35.         if(flag)
  36.         {
  37.                 std::cout << "After encrypting the number is " << Encrypting(code) << std::endl;
  38.         }
  39.         else
  40.         {
  41.                 std::cout << "After decrypting the number is " << Decrypting(code) << std::endl;
  42.         }

  43.         return 0;
  44. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-7 13:06:20 | 显示全部楼层
  1. 1890 1
  2. After encrypting the number is 6785
  3. 请按任意键继续. . .
复制代码

  1. 6785 0
  2. After decrypting the number is 1890
  3. 请按任意键继续. . .
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2018-12-17 21:35:39 | 显示全部楼层
lovesukie 发表于 2018-12-17 16:36
可是我还是没有发现我哪里错误了
emm

要描述清楚问题,你的程序有问题吗?有什么问题?
1.png
2.png
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-9-27 06:50

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表