0

[Bài] Phân loại theo bảng chữ cái

đã đăng vào 15, Tháng 3, 2026, 23:08

Cho dữ liệu (bạn không cần sắp xếp)

Đầu vào:

 *  [acme wiki instructions] (6)
 *  [adding a monitor to vgadb] (331)
 *  [background] (56)
 *  [blue gene port] (289)
 *  [books] (213)
 *  [broken hardware] (371)
 *  [compiling kernels] (8)
 *  [configuring a standalone cpu server] (14)
 *  [documentation] (261)
 *  [don't believe everything you read] (314)
 *  [staying up to date] (44)
 *  [summary of the plan 9 development environment] (21)

Hãy viết chương trình in chữ cái đầu tiêu đề mỗi bài viết, cho ra kết quả như sau:

Đầu ra:


A

 *  [acme wiki instructions] (6)
 *  [adding a monitor to vgadb] (331)

B

 *  [background] (56)
 *  [blue gene port] (289)
 *  [books] (213)
 *  [broken hardware] (371)

C

 *  [compiling kernels] (8)
 *  [configuring a standalone cpu server] (14)

D

 *  [documentation] (261)
 *  [don't believe everything you read] (314)

S

 *  [staying up to date] (44)
 *  [summary of the plan 9 development environment] (21)

Bình luận

Hãy đọc nội quy trước khi bình luận.



  • 0
    taolakerneldev  đã bình luận lúc 15, Tháng 3, 2026, 16:15

    Mình đang viết bằng ngôn ngữ awk chứ C thì dài lắm! Đang làm tool nhỏ tiện mang lên đây thui!

    awk 'BEGIN { ofirst="xx" }
        {
            first = toupper(substr($0, 5, 1))
            if(first != ofirst){
                printf "\n"
                print first
                printf "\n"
                ofirst=first
            }
            print
        }'