Hướng dẫn sort uppercase and lowercase letters in c++ - sắp xếp chữ hoa và chữ thường trong c ++

Xem thảo luận

Cải thiện bài viết

Lưu bài viết

  • Đọc
  • Bàn luận
  • Xem thảo luận

    Cải thiện bài viết

    Lưu bài viết

    Đọc

    Examples:

    Input : bAwutndekWEdkd
    Output :AbEdWddekkntuw
    Explanation:
    Here we can see that letter ‘A’, ’E’, ’W’ are sorted 
    as well as letters “b, d, d, d, e, k, k, n, t, u, w” are sorted 
    but both appears alternately in the string as far as possible.
    
    Input :abbfDDhGFBvdFDGBNDasZVDFjkb
    Output :BaBaDbDbDbDdDfFhFjFkGsGvNVZ

    Bàn luận
    2) Count upper case characters in another array uCount[] 
    3) Modify strings using lCount[] and uCount[] 

    C++

    #include

    Cho một chuỗi chứa chữ thường và chữ hoa. Sắp xếp nó theo cách mà các chữ cái viết hoa và chữ thường xuất hiện một cách khác nhưng theo một cách được sắp xếp.

    #define MAX 26

    1) Đếm các ký tự chữ thường trong một mảng lcount [] & nbsp; 2) Đếm các ký tự trường hợp trên trong một mảng khác ucount [] & nbsp; 3) sửa đổi chuỗi bằng Lcount [] và ucount [] & nbsp;

    {

    using namespace std;

    void alternateSort(string& s)

    AbEdWddekkntuw
    0____11
    AbEdWddekkntuw
    2

    AbEdWddekkntuw
    0____11
    AbEdWddekkntuw
    5

    #include 6#include 7#include 8#include 9

    #include 1using1

    #include 6using3using4#include 9

    AbEdWddekkntuw
    0using7

    AbEdWddekkntuw
    0____17
    AbEdWddekkntuw
    8
    AbEdWddekkntuw
    1 #include 0

    #include 1#include 2

    AbEdWddekkntuw
    8#include 4#include 5

    AbEdWddekkntuw
    0____11 namespace0

    #include 6namespace8

    AbEdWddekkntuw
    0namespace2 namespace3

    #include 1namespace2 namespace6

    #include 6std;7

    #include 1using7

    #include 1#include 2 std;1

    #include 6std;3#include 8 std;5

    #include 1namespace2 #define MAX 262

    #include 6#define MAX 264

    #include 6void3

    #include 1using7

    AbEdWddekkntuw
    0using7

    using7

    #include 1#include 2 #define MAX 267

    {

    AbEdWddekkntuw
    0alternateSort(string& s)3alternateSort(string& s)4alternateSort(string& s)5

    AbEdWddekkntuw
    0alternateSort(string& s)7

    AbEdWddekkntuw
    0alternateSort(string& s)9{0alternateSort(string& s)5

    using7

    #include 6std;3using4 void1

    AbEdWddekkntuw
    1 alternateSort(string& s)0

    Java

    {3 {4

    {3 {6

    {7 {8 {9

    {

    AbEdWddekkntuw
    00
    AbEdWddekkntuw
    01
    AbEdWddekkntuw
    02
    AbEdWddekkntuw
    1
    AbEdWddekkntuw
    04
    AbEdWddekkntuw
    05alternateSort(string& s)5

    AbEdWddekkntuw
    0
    AbEdWddekkntuw
    15
    AbEdWddekkntuw
    16

    {7

    AbEdWddekkntuw
    02
    AbEdWddekkntuw
    09

    AbEdWddekkntuw
    0____11
    AbEdWddekkntuw
    13

    ____10

    AbEdWddekkntuw
    1
    AbEdWddekkntuw
    19
    AbEdWddekkntuw
    20
    AbEdWddekkntuw
    1
    AbEdWddekkntuw
    22

    ____10

    AbEdWddekkntuw
    1
    AbEdWddekkntuw
    25
    AbEdWddekkntuw
    20
    AbEdWddekkntuw
    1
    AbEdWddekkntuw
    22

    #include 6#include 7#include 8#include 9

    #include 1using1

    #include 6using3using4#include 9

    AbEdWddekkntuw
    0using7

    ____10

    AbEdWddekkntuw
    7
    AbEdWddekkntuw
    8
    AbEdWddekkntuw
    1
    AbEdWddekkntuw
    33
    AbEdWddekkntuw
    34
    AbEdWddekkntuw
    35

    #include 1#include 2

    AbEdWddekkntuw
    38

    AbEdWddekkntuw
    0{

    Is

    AbEdWddekkntuw
    70namespace8

    AbEdWddekkntuw
    0namespace2 namespace3

    #include 1namespace2 namespace6

    AbEdWddekkntuw
    70std;7

    #include 6using7

    #include 1#include 2 std;1

    AbEdWddekkntuw
    70#define MAX 264

    #include 1namespace2 #define MAX 262

    #include 6#define MAX 264

    #include 1#include 2 #define MAX 267

    #include 6using7

    #include 1using7

    #include 6std;3using4 void1

    AbEdWddekkntuw
    0using7

    AbEdWddekkntuw
    1 alternateSort(string& s)0

    AbEdWddekkntuw
    0#include 19alternateSort(string& s)4alternateSort(string& s)5

    AbEdWddekkntuw
    0#include 23

    using7

    using7

    C#

    Java

    {3 {4

    {3 {6

    {7 {8 {9

    AbEdWddekkntuw
    0{

    AbEdWddekkntuw
    00
    AbEdWddekkntuw
    01
    AbEdWddekkntuw
    02
    AbEdWddekkntuw
    1
    AbEdWddekkntuw
    04
    AbEdWddekkntuw
    05alternateSort(string& s)5

    {7

    AbEdWddekkntuw
    02
    AbEdWddekkntuw
    09

    #include 1

    AbEdWddekkntuw
    15#include 49

    AbEdWddekkntuw
    0____11
    AbEdWddekkntuw
    13

    ____10

    AbEdWddekkntuw
    1
    AbEdWddekkntuw
    19
    AbEdWddekkntuw
    20
    AbEdWddekkntuw
    1
    AbEdWddekkntuw
    22

    ____10

    AbEdWddekkntuw
    1
    AbEdWddekkntuw
    25
    AbEdWddekkntuw
    20
    AbEdWddekkntuw
    1
    AbEdWddekkntuw
    22

    ____10

    AbEdWddekkntuw
    7
    AbEdWddekkntuw
    8
    AbEdWddekkntuw
    1
    AbEdWddekkntuw
    33
    AbEdWddekkntuw
    34
    AbEdWddekkntuw
    35

    AbEdWddekkntuw
    70#include 7#include 8#include 9

    #include 6using1

    AbEdWddekkntuw
    70using3using4#include 9

    #include 1using7

    #include 1#include 2

    AbEdWddekkntuw
    38

    #include 1{

    Is

    AbEdWddekkntuw
    70#include 93

    AbEdWddekkntuw
    0namespace2
    AbEdWddekkntuw
    62

    #include 1namespace2

    AbEdWddekkntuw
    67
    AbEdWddekkntuw
    34
    AbEdWddekkntuw
    69

    AbEdWddekkntuw
    70using04

    #include 6using7

    AbEdWddekkntuw
    70
    AbEdWddekkntuw
    76
    AbEdWddekkntuw
    15
    AbEdWddekkntuw
    78#include 8
    AbEdWddekkntuw
    80

    AbEdWddekkntuw
    70#define MAX 264

    #include 1namespace2

    AbEdWddekkntuw
    87
    AbEdWddekkntuw
    34
    AbEdWddekkntuw
    69

    #include 6#define MAX 264

    AbEdWddekkntuw
    70void3

    #include 6using7

    #include 1using7

    #include 6std;3using4 void1

    AbEdWddekkntuw
    0using7

    AbEdWddekkntuw
    1 alternateSort(string& s)0

    AbEdWddekkntuw
    0{

    Java

    #include 1using46

    AbEdWddekkntuw
    0using7

    using7

    Python3

    {3 {4

    {3 {6

    {7 {8 {9

    AbEdWddekkntuw
    00
    AbEdWddekkntuw
    01
    AbEdWddekkntuw
    02
    AbEdWddekkntuw
    1
    AbEdWddekkntuw
    04
    AbEdWddekkntuw
    05alternateSort(string& s)5

    {7

    AbEdWddekkntuw
    02
    AbEdWddekkntuw
    09

    AbEdWddekkntuw
    0____11
    AbEdWddekkntuw
    13

    ____10

    AbEdWddekkntuw
    7 using66using67 using68using94

    #include 1#include 2using97

    #include 6using99namespace00namespace01namespace02

    Các

    #include 1using1namespace13

    #include 6namespace15namespace00namespace01namespace02

    Các

    AbEdWddekkntuw
    0using66using51
    AbEdWddekkntuw
    34

    ____10namespace32using51

    AbEdWddekkntuw
    34

    ____10namespace36using51

    AbEdWddekkntuw
    34

    AbEdWddekkntuw
    0namespace2namespace41

    #include 1namespace2namespace444using50 namespace46

    namespace47namespace48using51using51

    AbEdWddekkntuw
    34namespace52

    #include 6using66namespace08using51 namespace10

    #include 1#include 2namespace44using50namespace52

    Các

    #include 6namespace36namespace08using51 namespace10

    #include 6namespace48namespace02using51 namespace10

    #include 1namespace2namespace86using50 namespace46

    namespace47namespace90using51using51

    AbEdWddekkntuw
    34namespace52

    #include 6namespace32namespace08using51 namespace10

    #include 1#include 2namespace86using50namespace52

    Các

    #include 6namespace36namespace08using51 namespace10

    #include 6namespace48namespace02using51 namespace10

    AbEdWddekkntuw
    0std;27std;28

    #include 1namespace2namespace86using50 namespace46

    std;32std;29

    AbEdWddekkntuw
    69

    namespace47namespace90using51using51 AbEdWddekkntuw34namespace52

    std;35

    std;36std;37

    #include 6namespace32namespace08using51 namespace10

    Các

    #include 6namespace90namespace02using51 namespace10

    std;29 using51 alternateSort(string& s)4

    JavaScript

    std;36std;39 std;40

    #include 1std;42 std;43

    #include 1std;42 #include 46

    #include 6std;71std;72std;73

    std;67using1

    namespace47std;77std;78std;73

    #include 1using7

    #include 1std;42 std;49std;50std;51

    #include 1std;42 std;54

    AbEdWddekkntuw
    20 std;56

    #include 1std;42 std;59

    AbEdWddekkntuw
    20 std;56

    #include 1

    AbEdWddekkntuw
    7
    AbEdWddekkntuw
    8std;42 #include 0

    #include 6std;94std;72std;96

    #include 6using04

    std;67using7

    std;67#include 2 std;69

    namespace47#define MAX 264

    #include 1namespace2 namespace3

    #include 6std;94std;78#define MAX 2612

    #include 6void3

    std;67using7

    #include 1using7

    std;67namespace2 std;87

    std;36using7

    namespace47#include 93

    std;36#define MAX 2632

    #define MAX 2633

    Output: 

    AbEdWddekkntuw

    std;67#include 2 #include 96 O(n).

    std;67namespace2 #define MAX 2603O(max(n,26)), where n is the length of the string.

    std;67#include 2 #define MAX 267


    Phân loại trường hợp nhạy cảm là gì?

    Sắp xếp trên cơ sở các giá trị ASCII phân biệt các chữ cái viết hoa với các chữ cái viết thường và dẫn đến một thứ tự nhạy cảm trường hợp., and results in a case-sensitive order.

    Vô thường có đến trước trường hợp trên không?

    Tất cả các chữ cái chữ hoa đến trước các chữ cái chữ thường.Nếu hai chữ cái là cùng một trường hợp, thì thứ tự chữ cái được sử dụng để so sánh chúng.. If two letters are the same case, then alphabetic order is used to compare them.

    Làm thế nào để bạn sắp xếp chữ thường và chữ hoa trong java?

    Approach:..
    Chúng tôi sẽ sử dụng hai danh sách ArrayL
    Sau khi thêm các phần tử vào danh sách, chúng tôi sẽ sắp xếp danh sách bằng các bộ sưu tập.Sắp xếp (danh sách) Phương pháp ..
    Sau khi sắp xếp, chúng tôi sẽ đi qua chuỗi và kiểm tra cụ thể trường hợp và lưu trữ phần tử ở vị trí chính xác ..

    Làm cách nào để sắp xếp các ký tự trong một chuỗi?

    Logic chính là phương thức tochararray () của lớp chuỗi trên chuỗi đầu vào để tạo một mảng ký tự cho chuỗi đầu vào.Bây giờ sử dụng phương thức mảng.sort (char c []) để sắp xếp mảng ký tự.Sử dụng hàm tạo lớp chuỗi để tạo một chuỗi được sắp xếp từ mảng char.use Arrays. sort(char c[]) method to sort character array. Use the String class constructor to create a sorted string from a char array.