1 条题解
-
2
首先我们读题后会发现这个其实就是凯撒密码
但是有一点点细节:
请注意:毒瘤出题人并不会放过你,而是反手就来了一句话
可能会有小部分数据含有非大写字符,请照常输出这些字符。 但是保证全部都是ASKII字符,而非Unicode字符(要不然你TM得用python了)
而且题目并没有说偏移量不能超过26。所以需要注意mod26
// P3600 标准程序 #include <iostream> #include <string> using namespace std; int n;//偏移量 string h,a;//输入,输出的字符串 char alpa[60]; int main(){ cin >> n; cin >> h; char al = 'A'-1;//目前的字母 while (n>25) n%=26;//防止超过26,不过这里的while可以换成if for (int i = 1;i<=26;i++){ al++; alpa[i]=al; } //生成对应的加密字符 al = 'A'-1; for (int i = 27;i<=51;i++){ al++; alpa[i]=al; } //这里是防止越界,由于前面mod26过,所以这里<=51就行 for (int i = 0;i<h.size();i++){ if (h[i]>='A'&&'Z'>=h[i])a+=alpa[h[i]-'A'+1+n]; else a+=h[i]; } //生成 cout << a; }
抄题解的人将会获得作弊者TAG
当然,为了各位学习汇编的人学习快乐,这里也把汇编的放一下:
n: .zero 4 h[abi:cxx11]: .zero 32 a[abi:cxx11]: .zero 32 alpa: .zero 60 main: push rbp mov rbp, rsp push rbx sub rsp, 24 mov esi, OFFSET FLAT:n mov edi, OFFSET FLAT:_ZSt3cin call std::basic_istream<char, std::char_traits<char> >::operator>>(int&) mov esi, OFFSET FLAT:h[abi:cxx11] mov edi, OFFSET FLAT:_ZSt3cin call std::basic_istream<char, std::char_traits<char> >& std::operator>><char, std::char_traits<char>, std::allocator<char> >(std::basic_istream<char, std::char_traits<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) mov BYTE PTR [rbp-17], 64 jmp .L2 .L3: mov edx, DWORD PTR n[rip] movsx rax, edx imul rax, rax, 1321528399 shr rax, 32 sar eax, 3 mov ecx, edx sar ecx, 31 sub eax, ecx imul ecx, eax, 26 mov eax, edx sub eax, ecx mov DWORD PTR n[rip], eax .L2: mov eax, DWORD PTR n[rip] cmp eax, 25 jg .L3 mov DWORD PTR [rbp-24], 1 jmp .L4 .L5: movzx eax, BYTE PTR [rbp-17] add eax, 1 mov BYTE PTR [rbp-17], al mov eax, DWORD PTR [rbp-24] cdqe movzx edx, BYTE PTR [rbp-17] mov BYTE PTR alpa[rax], dl add DWORD PTR [rbp-24], 1 .L4: cmp DWORD PTR [rbp-24], 26 jle .L5 mov BYTE PTR [rbp-17], 64 mov DWORD PTR [rbp-28], 27 jmp .L6 .L7: movzx eax, BYTE PTR [rbp-17] add eax, 1 mov BYTE PTR [rbp-17], al mov eax, DWORD PTR [rbp-28] cdqe movzx edx, BYTE PTR [rbp-17] mov BYTE PTR alpa[rax], dl add DWORD PTR [rbp-28], 1 .L6: cmp DWORD PTR [rbp-28], 51 jle .L7 mov DWORD PTR [rbp-32], 0 jmp .L8 .L13: mov eax, DWORD PTR [rbp-32] cdqe mov rsi, rax mov edi, OFFSET FLAT:h[abi:cxx11] call std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned long) movzx eax, BYTE PTR [rax] cmp al, 64 jle .L9 mov eax, DWORD PTR [rbp-32] cdqe mov rsi, rax mov edi, OFFSET FLAT:h[abi:cxx11] call std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned long) movzx eax, BYTE PTR [rax] cmp al, 90 jg .L9 mov eax, 1 jmp .L10 .L9: mov eax, 0 .L10: test al, al je .L11 mov eax, DWORD PTR [rbp-32] cdqe mov rsi, rax mov edi, OFFSET FLAT:h[abi:cxx11] call std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned long) movzx eax, BYTE PTR [rax] movsx eax, al lea edx, [rax-64] mov eax, DWORD PTR n[rip] add eax, edx cdqe movzx eax, BYTE PTR alpa[rax] movsx eax, al mov esi, eax mov edi, OFFSET FLAT:a[abi:cxx11] call std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator+=(char) jmp .L12 .L11: mov eax, DWORD PTR [rbp-32] cdqe mov rsi, rax mov edi, OFFSET FLAT:h[abi:cxx11] call std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned long) movzx eax, BYTE PTR [rax] movsx eax, al mov esi, eax mov edi, OFFSET FLAT:a[abi:cxx11] call std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator+=(char) .L12: add DWORD PTR [rbp-32], 1 .L8: mov eax, DWORD PTR [rbp-32] movsx rbx, eax mov edi, OFFSET FLAT:h[abi:cxx11] call std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const cmp rbx, rax setb al test al, al jne .L13 mov esi, OFFSET FLAT:a[abi:cxx11] mov edi, OFFSET FLAT:_ZSt4cout call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) mov eax, 0 mov rbx, QWORD PTR [rbp-8] leave ret __static_initialization_and_destruction_0(int, int): push rbp mov rbp, rsp sub rsp, 16 mov DWORD PTR [rbp-4], edi mov DWORD PTR [rbp-8], esi cmp DWORD PTR [rbp-4], 1 jne .L17 cmp DWORD PTR [rbp-8], 65535 jne .L17 mov edi, OFFSET FLAT:_ZStL8__ioinit call std::ios_base::Init::Init() [complete object constructor] mov edx, OFFSET FLAT:__dso_handle mov esi, OFFSET FLAT:_ZStL8__ioinit mov edi, OFFSET FLAT:_ZNSt8ios_base4InitD1Ev call __cxa_atexit mov edi, OFFSET FLAT:h[abi:cxx11] call std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string() [complete object constructor] mov edx, OFFSET FLAT:__dso_handle mov esi, OFFSET FLAT:h[abi:cxx11] mov edi, OFFSET FLAT:_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev call __cxa_atexit mov edi, OFFSET FLAT:a[abi:cxx11] call std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string() [complete object constructor] mov edx, OFFSET FLAT:__dso_handle mov esi, OFFSET FLAT:a[abi:cxx11] mov edi, OFFSET FLAT:_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev call __cxa_atexit .L17: nop leave ret _GLOBAL__sub_I_n: push rbp mov rbp, rsp mov esi, 65535 mov edi, 1 call __static_initialization_and_destruction_0(int, int) pop rbp ret
- 1
信息
- ID
- 4
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 7
- 标签
- 递交数
- 63
- 已通过
- 14
- 上传者