#32763: c++ 四行解


20060705sean (pneumonoultramicroscopicsilico...)

學校 : 高雄市立高雄高級中學
編號 : 77753
來源 : [140.112.239.216]
最後登入時間 :
2024-11-09 09:00:20
c518. 3. 字串加密 -- 2017高雄市資訊學科能力複賽 | From: [163.32.78.54] | 發表日期 : 2022-11-03 20:57

volia

 

#include <bits/stdc++.h>
using namespace std;string text, origin, after, result = "", allchar = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";vector<int> chart(128);
void replace(string::iterator first, string::iterator last, char old_char, char new_char) {for (;first != last;first++) {if (*first == old_char) *first = new_char;}}
int main() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int n, m, i;for (i = 0;i < (int)allchar.size();i++) {chart[(int)allchar[i]] = i;}cin >> n >> m;cin >> text >> origin >> after;for (i = 0;i < m;i++) {replace(code.begin(), code.end(), origin[i], after[i]);}for (i = 0;i < n;i++) {putchar(code[chart[(int)text[i]]]);}}

 
ZeroJudge Forum