Làm cách nào để bạn chuyển đổi tên cột excel thành số?

Chúng tôi đã thảo luận Chuyển đổi từ số cột sang tên cột Excel. Trong bài viết này, đảo ngược được thảo luận

Show

    Đưa ra một tiêu đề cột như xuất hiện trong một trang tính Excel, hãy trả về số cột tương ứng của nó

    column  column number
      A  ->  1
      B  ->  2
      C  ->  3
      ...
      Z  ->  26
      AA ->  27
      AB ->  28 

    ví dụ.  

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.

    Đề nghị thực hành

    Bảng tính Excel. Phần 2

    Thử nó

    Cách tiếp cận. Quá trình này tương tự như chuyển đổi nhị phân sang thập phân.
    Ví dụ, để chuyển đổi AB, công thức là 26 * 1 + 2.

    Như một ví dụ khác,

    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1

    Vì vậy, nó rất giống với việc chuyển đổi nhị phân sang thập phân giữ cơ số là 26.
    Lấy đầu vào dưới dạng chuỗi và duyệt chuỗi đầu vào từ trái sang phải và tính toán kết quả như sau.

    result = 26*result + s[i] - 'A' + 1

    Kết quả sẽ là tổng của 

    Làm cách nào để bạn chuyển đổi tên cột excel thành số?
    .

    Thực hiện

    C++




    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    15

    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    16

    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    17

     

    ________ 218 ________ 219 ________ 10

     

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    1

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    2
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    3

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    4

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    6

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    8

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    2
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    1

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    3
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    4
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    5
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    6
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    7

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    4

    result = 26*result + s[i] - 'A' + 1
    0
    result = 26*result + s[i] - 'A' + 1
    1

    result = 26*result + s[i] - 'A' + 1
    0
    result = 26*result + s[i] - 'A' + 1
    3
    result = 26*result + s[i] - 'A' + 1
    4
    result = 26*result + s[i] - 'A' + 1
    5

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    result = 26*result + s[i] - 'A' + 1
    7

     

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    result = 26*result + s[i] - 'A' + 1
    9
    result = 26*result + s[i] - 'A' + 1
    40

    result = 26*result + s[i] - 'A' + 1
    7

     

    result = 26*result + s[i] - 'A' + 1
    42

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    2
    result = 26*result + s[i] - 'A' + 1
    44

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    4

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    result = 26*result + s[i] - 'A' + 1
    47____348
    result = 26*result + s[i] - 'A' + 1
    49

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    result = 26*result + s[i] - 'A' + 1
    9
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    152

    result = 26*result + s[i] - 'A' + 1
    7

    Java




    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    154

    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    155

    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    156
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    157

    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    156
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    159

     

    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    160
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    161

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    4

     

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    1

    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    164
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    2
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    166

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    4

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    6

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    8

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    2
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    174
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    175
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    176

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    3
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    4
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    2
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    181
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    175
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    183

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    4

    result = 26*result + s[i] - 'A' + 1
    0____2187____2188
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    176

    result = 26*result + s[i] - 'A' + 1
    0______2191______34
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    193
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    194
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    176

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    result = 26*result + s[i] - 'A' + 1
    7

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    result = 26*result + s[i] - 'A' + 1
    9
    result = 26*result + s[i] - 'A' + 1
    40

    result = 26*result + s[i] - 'A' + 1
    7

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    03

    ________ 104 ________ 2164 ________ 106 ________ 107

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    4

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    10____348
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    12

    result = 26*result + s[i] - 'A' + 1
    7

    result = 26*result + s[i] - 'A' + 1
    7

     

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    15

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    16

    Python3




    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    17

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    18

     

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    19

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    20
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    21

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    23

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    25

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    27____128
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    175
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    176

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    3
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    33
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    34
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    35
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    4
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    37
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    38

    result = 26*result + s[i] - 'A' + 1
    0______127
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    41
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    28
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    188
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    176

    result = 26*result + s[i] - 'A' + 1
    0______127
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    193
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    28
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    49
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    50
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    51
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    49
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    4
    result = 26*result + s[i] - 'A' + 1
    4
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    55
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    193
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    194
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    176

     

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    result = 26*result + s[i] - 'A' + 1
    9
    result = 26*result + s[i] - 'A' + 1
    40

     

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    62

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    63
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    64
    result = 26*result + s[i] - 'A' + 1
    48
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    12

     

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    67

    C#




    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    68

    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    155

    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    18
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    71

     

    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    160
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    161

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    4

     

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    1

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    04
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    164
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    2
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    79
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    80
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    81

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    4

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    6

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    8

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    2
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    1

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    3
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    4
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    2
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    94

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    4

    result = 26*result + s[i] - 'A' + 1
    0
    result = 26*result + s[i] - 'A' + 1
    1

    result = 26*result + s[i] - 'A' + 1
    0____200____34
    result = 26*result + s[i] - 'A' + 1
    5

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    result = 26*result + s[i] - 'A' + 1
    7

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    result = 26*result + s[i] - 'A' + 1
    9
    result = 26*result + s[i] - 'A' + 1
    40

    result = 26*result + s[i] - 'A' + 1
    7

     

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    03

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    04
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    164
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    06
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    13
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    80
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    15

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    4

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    18
    result = 26*result + s[i] - 'A' + 1
    48
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    12

    result = 26*result + s[i] - 'A' + 1
    7

    result = 26*result + s[i] - 'A' + 1
    7

     

    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    23

    Javascript




    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    24

     

    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    25

    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    155

     

    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    27

    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    28
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    29

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    4

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    6

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    8

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    36

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    3
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    39

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    4

    result = 26*result + s[i] - 'A' + 1
    0
    result = 26*result + s[i] - 'A' + 1
    1

    result = 26*result + s[i] - 'A' + 1
    0____245____34
    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    47

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    result = 26*result + s[i] - 'A' + 1
    7

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    5
    result = 26*result + s[i] - 'A' + 1
    9
    result = 26*result + s[i] - 'A' + 1
    40

    result = 26*result + s[i] - 'A' + 1
    7

    Input: A
    Output: 1
    A is the first column so the output is 1.
    
    Input: AA
    Output: 27
    The columns are in order A, B, ..., Y, Z, AA ..
    So, there are 26 columns after which AA comes.
    03

    ________ 255 ________ 348 ________ 112

     

    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    58

     

    To convert CDA,
    3*26*26 + 4*26 + 1
    = 26(3*26 + 4) + 1
    = 26(0*26 + 3*26 + 4) + 1
    59

    Đầu ra

    result = 26*result + s[i] - 'A' + 1
    4

    Phân tích độ phức tạp.  

    • Thời gian phức tạp. O(n), trong đó n là độ dài của chuỗi đầu vào
    • Độ phức tạp của không gian. Ô(1).
      Vì không cần thêm dung lượng.

    Bài viết này được đóng góp bởi Sahil Rajput. Nếu bạn thích GeeksforGeeks và muốn đóng góp, bạn cũng có thể viết một bài báo bằng cách sử dụng write. chuyên viên máy tính. org hoặc gửi bài viết của bạn tới review-team@geeksforgeeks. tổ chức. Xem bài viết của bạn xuất hiện trên trang chính của GeeksforGeeks và trợ giúp các Geeks khác