Character code

Introduction

I would like to summarize what I learned a little from studying atcoder.

ASCII Do you know about character codes? According to Wikipedia

A character code is provided for each character (may not be a single character) when a sentence is handled in the form of text rather than as graphic data such as an image in an electronic medium such as a computer. It's a code. (wikipedia)

There is. Simply put, it's like a rule (code) for expressing characters on a computer. As a type

Character code Use Amount of information
ASCII Codes representing alphabets and numbers 7-bit code
SJIS Code that can express Japanese 16-bit code
EUC-JIS Code for expressing Japanese on UNIX 16-bit code
Unicode Codes that represent characters around the world 16-21 code
UTF-8 Compatible with the most popular code, ASCII 3 bytes

That's about it. I think there are many people who have seen UTF-8.

Atcoder146 B - ROT N

Problem statement There is a string S consisting only of uppercase letters. It is also given the integer N. Output a character string in which each character of S is replaced with the character after N in alphabetical order. However, the letter after Z in alphabetical order is regarded as A.

I used the ASCII idea above in solving this problem.

test.py


N = int(input())
S = input()
def change():
    s=[]
    for i in range(len(S)):
        m = ((ord(S[i])-ord("A")+N) % 26)
        s.append(chr(m+ord("A")))
    return "".join(s)
print(change())

Please forgive me for the dung code (laughs) The most important thing here is ʻOrd ()andchr ()` functions. This function is a function that converts letters and numbers written in ASCII into pre-assigned numbers and letters. [ASCII code]: http://www12.plala.or.jp/mz80k2/electronics/ascii/ascii.html For example, the letter "A" is ** 65 ** according to the ASCII character code. Also, if you use a function chr("a")I write it like this. On the contrary, if you want to assign a number to asciiord(65)It will be like that.

At the end

There are various character codes, so it's interesting to study! !!

Recommended Posts

Character code
python character code
About Python3 character code
Source code character code check script
2.x, 3.x character code of python
Character code learned in Python
Character code † darkness † encounter report part1
Bad code
Linux commands related to character code
Handling of character code of file in IronPython
Read the file by specifying the character code.
[Python] Get the character code of the file
Color code list
Write python-like code
FFT pseudo code
[Python] [chardet] Automatic detection of character code of file
Character range / character string range
Links and memos of Python character code strings
[Python] Algorithm-aware code
Replace'a character'with'specified character'
Convert the character code of the file with Python3
QR code display
Zip code geocoding
PyCharm code interpolation
python2 series / 3 series, character code and print statement / command line
# Function that returns the character code of a string