#include <stdio.h>
#include <string.h>
// ฟังก์ชันโปรโตไทป์
void encodeMessage(char str[50], int n);
int main() {
char str[50];
int n;
// รับข้อมูลอินพุต
scanf("%[^\n]", str
); // อ่านสตริงรวมช่องว่าง scanf("%d", &n
); // รับค่า n
// เรียกฟังก์ชัน encodeMessage
encodeMessage(str, n);
// แสดงข้อความที่ถูกเข้ารหัส
return 0;
}
// ฟังก์ชัน encodeMessage
void encodeMessage(char str[50], int n) {
for (int i = 0; str[i] != '\0'; i++) {
// ตัวอักษร A-Z
if (str[i] >= 'A' && str[i] <= 'Z') {
str[i] = 'A' + (str[i] - 'A' + n) % 26; // เลื่อนในช่วง A-Z
}
// ตัวอักษร a-z
else if (str[i] >= 'a' && str[i] <= 'z') {
str[i] = 'a' + (str[i] - 'a' + n) % 26; // เลื่อนในช่วง a-z
}
// ตัวเลข 0-9
else if (str[i] >= '0' && str[i] <= '9') {
str[i] = '0' + (str[i] - '0' + n) % 10; // เลื่อนในช่วง 0-9
}
// อักขระพิเศษและช่องว่าง (ไม่เปลี่ยนแปลง)
else {
str[i] = str[i];
}
}
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KCi8vIOC4n+C4seC4h+C4geC5jOC4iuC4seC4meC5guC4m+C4o+C5guC4leC5hOC4l+C4m+C5jAp2b2lkIGVuY29kZU1lc3NhZ2UoY2hhciBzdHJbNTBdLCBpbnQgbik7CgppbnQgbWFpbigpIHsKICAgIGNoYXIgc3RyWzUwXTsKICAgIGludCBuOwoKICAgIC8vIOC4o+C4seC4muC4guC5ieC4reC4oeC4ueC4peC4reC4tOC4meC4nuC4uOC4lQogICAgc2NhbmYoIiVbXlxuXSIsIHN0cik7IC8vIOC4reC5iOC4suC4meC4quC4leC4o+C4tOC4h+C4o+C4p+C4oeC4iuC5iOC4reC4h+C4p+C5iOC4suC4hwogICAgc2NhbmYoIiVkIiwgJm4pOyAgICAgIC8vIOC4o+C4seC4muC4hOC5iOC4siBuCgogICAgLy8g4LmA4Lij4Li14Lii4LiB4Lif4Lix4LiH4LiB4LmM4LiK4Lix4LiZIGVuY29kZU1lc3NhZ2UKICAgIGVuY29kZU1lc3NhZ2Uoc3RyLCBuKTsKCiAgICAvLyDguYHguKrguJTguIfguILguYnguK3guITguKfguLLguKHguJfguLXguYjguJbguLnguIHguYDguILguYnguLLguKPguKvguLHguKoKICAgIHByaW50ZigiJXNcbiIsIHN0cik7CgogICAgcmV0dXJuIDA7Cn0KCi8vIOC4n+C4seC4h+C4geC5jOC4iuC4seC4mSBlbmNvZGVNZXNzYWdlCnZvaWQgZW5jb2RlTWVzc2FnZShjaGFyIHN0cls1MF0sIGludCBuKSB7CiAgICBmb3IgKGludCBpID0gMDsgc3RyW2ldICE9ICdcMCc7IGkrKykgewogICAgICAgIC8vIOC4leC4seC4p+C4reC4seC4geC4qeC4oyBBLVoKICAgICAgICBpZiAoc3RyW2ldID49ICdBJyAmJiBzdHJbaV0gPD0gJ1onKSB7CiAgICAgICAgICAgIHN0cltpXSA9ICdBJyArIChzdHJbaV0gLSAnQScgKyBuKSAlIDI2OyAvLyDguYDguKXguLfguYjguK3guJnguYPguJnguIrguYjguKfguIcgQS1aCiAgICAgICAgfQogICAgICAgIC8vIOC4leC4seC4p+C4reC4seC4geC4qeC4oyBhLXoKICAgICAgICBlbHNlIGlmIChzdHJbaV0gPj0gJ2EnICYmIHN0cltpXSA8PSAneicpIHsKICAgICAgICAgICAgc3RyW2ldID0gJ2EnICsgKHN0cltpXSAtICdhJyArIG4pICUgMjY7IC8vIOC5gOC4peC4t+C5iOC4reC4meC5g+C4meC4iuC5iOC4p+C4hyBhLXoKICAgICAgICB9CiAgICAgICAgLy8g4LiV4Lix4Lin4LmA4Lil4LiCIDAtOQogICAgICAgIGVsc2UgaWYgKHN0cltpXSA+PSAnMCcgJiYgc3RyW2ldIDw9ICc5JykgewogICAgICAgICAgICBzdHJbaV0gPSAnMCcgKyAoc3RyW2ldIC0gJzAnICsgbikgJSAxMDsgLy8g4LmA4Lil4Li34LmI4Lit4LiZ4LmD4LiZ4LiK4LmI4Lin4LiHIDAtOQogICAgICAgIH0KICAgICAgICAvLyDguK3guLHguIHguILguKPguLDguJ7guLTguYDguKjguKnguYHguKXguLDguIrguYjguK3guIfguKfguYjguLLguIcgKOC5hOC4oeC5iOC5gOC4m+C4peC4teC5iOC4ouC4meC5geC4m+C4peC4hykKICAgICAgICBlbHNlIHsKICAgICAgICAgICAgc3RyW2ldID0gc3RyW2ldOwogICAgICAgIH0KICAgIH0KfQo=