【YACS 2020 年 3 月月赛 丙组】 数字加密

Leo2011 大气压强

题目 Link


先找规律,不难发现:

所以,对于最后一位的转换,只需要求出 密文最后一位的值就是明文的值,不需要写那么复杂用一堆 if。

后面的倒推就可以了,无非就是两次交换。注意第一位可能是 0,所以建议用字符串存.


ACCode:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*Code by Leo2011*/
#include <bits/stdc++.h>

#define log printf
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define FOR(i, l, r) for (int(i) = (l); (i) <= (r); ++(i))
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(nullptr); \
cout.tie(nullptr);

using namespace std;

typedef __int128 i128;
typedef long long ll;
typedef pair<int, int> PII;

string s, ans;

template <typename T>

inline T read() {
T sum = 0, fl = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') fl = -1;
for (; isdigit(ch); ch = getchar()) sum = sum * 10 + ch - '0';
return sum * fl;
}

template <typename T>

inline void write(T x) {
if (x < 0) {
putchar('-'), write<T>(-x);
return;
}
static T sta[35];
int top = 0;
do { sta[top++] = x % 10, x /= 10; } while (x);
while (top) putchar(sta[--top] + 48);
}

int main() {
IOS;
cin >> s;
FOR(i, 0, 3) ans += '0' + (9 - (s[i] - '0'));
swap(ans[0], ans[3]);
swap(ans[1], ans[2]);
cout << ans;
return 0;
}

AC 记录~

  • 标题: 【YACS 2020 年 3 月月赛 丙组】 数字加密
  • 作者: Leo2011
  • 创建于 : 2024-06-27 23:21:24
  • 更新于 : 2024-09-01 18:22:15
  • 链接: https://leo2011.eu.org/2024/06/27/yacs-2020-nian-3-yue-yue-sai-bing-zu-shu-zi-jia-mi/
  • 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。
评论
目录
【YACS 2020 年 3 月月赛 丙组】 数字加密