Names are sorted by dictionary of Pascal Programming

Updated on technology 2024-05-17
11 answers
  1. Anonymous users2024-02-10

    vari,j:integer;

    n:integer;

    a:array[1..maxint] of string;

    k:string;

    beginread(n);

    for i:=1 to n do readln(a[i]);

    for i:=1 to n-1 do

    for j:=i+1 to n do

    if ifor i:=1 to n do

    writeln(a[i]);

    end.Watchtower owner, absolutely correct (regardless of how many).

  2. Anonymous users2024-02-09

    Strings in pascal can be compared in size.

  3. Anonymous users2024-02-08

    If it's an all-uppercase or all-lowercase string, it's pretty straightforward.

    Just sort by the sorting algorithm (just change the original data type from integer to string).

    Do it with an array of characters"Outputs strings in lexicographic order"It's much more complicated, so it's recommended to use strings instead.

  4. Anonymous users2024-02-07

    var a:array[0..10000] of string;

    n,i:longint;

    procedure sort(i1,j1:longint);

    var i,j:longint;

    n,s:string;

    begini:=i1;

    j:=j1;

    n:=a[(i+j) div 2];Find a reference to compare repeat

    while a[i]n do dec(j);

    if i<=j then

    begins:=a[i];a[i]:=a[j];a[j]:=s;exchange inc(i); dec(j);

    end;until i>j;

    if iif i1end;

    begin file.

    readln(n);The number of strings read, remember to wrap (wraps are also characters) for i:=1 to n do readln(a[i]); N strings are read.

    sort(1,n);Quick sort.

    for i:=1 to n do writeln(a[i]);N strings are output.

    File output. end.

  5. Anonymous users2024-02-06

    In fact, the method is the same as the selection order.

  6. Anonymous users2024-02-05

    Fast rowing, the string is the same as normal data.

  7. Anonymous users2024-02-04

    main()

    if(p!=i)

    puts(cs[i]);printf("");

    In the first for statement of this program, use the gets function to enter five name strings. As mentioned above, the C language allows a two-dimensional array to be treated as multiple one-dimensional arrays, and this program explains that cs[5][20] is a two-dimensional character array, which can be divided into five one-dimensional arrays cs[0], cs[1], cs[2], cs[3], and cs[4]. So it's legal to use cs[i] in the gets function.

    In the second for statement, another for statement is nested to form a double loop. This double loop completes the work in alphabetical order. In the outer loop, copy the name string from the character array cs[i] to the array st, and assign the subscript i to p.

    After entering the inner loop, compare the strings after CS[I] with st, and if there is something smaller than st, copy the string into ST and assign its subscript to P. After the inner loop is completed, if p does not equal i, there is a smaller string than cs[i], so the contents of cs[i] and st are exchanged. So far, the sort value of the ith element of the array cs has been determined.

    That string is then output. After the outer loop is complete, all sorting and output are completed.

  8. Anonymous users2024-02-03

    Quick sort is an improvement on bubbling sorting. Its basic idea is: divide the data to be sorted into two independent parts by lying sorting, all the data of one part are smaller than all the data of the other part, and then quickly sort the two parts of the data according to the secondary method, and the whole sorting process can be carried out recursively, so as to achieve that the whole data becomes an ordered sequence.

    Suppose the array you want to sort is a[1] ......a[n], first select an arbitrary data (usually the first data) as the key data, and then put all the numbers larger than it in front of it, and all the numbers larger than it behind it, this process is called a lying quick sort. The algorithm for a lying quicksort is:

    1) Set two variables i and j, i:=1 and j:=n at the beginning of sorting;

    2) Take the first array element as the key data and assign a value to x, that is, x:=a[1];

    5) Repeat step until i>j;

    An example of the detailed process is as follows:

    Original order: [26 5 37 1 61 11 59 15 48 19].

    I: [19 5 15 1 11] 26 [59 61 48 37].

    II: [11 5 15 1] 19 26 [59 61 48 37].

    Three: [1 5] 11 [15] 19 26 [59 61 48 37].

    IV: 1 5 11 [15] 19 26 [59 61 48 37].

    V: 1 5 11 15 19 26 [59 61 48 37].

    Xx: 1 5 11 15 19 26 [37 48] 59 [61].

    VII: 1 5 11 15 19 26 37 48 59 [61].

    VIII: 1 5 11 15 19 26 37 48 59 61

    The quicksort method is the fastest and most efficient of all sorting methods. The procedure is as follows:

    var a:array[0..10] of integer;

    n:integer;

    procedure qsort(l,r:longint);

    var i,j,m:longint;

    beginm:=a[l];

    i:=l;j:=r;

    repeat

    while a[i]m do dec(j);

    if i<=j then begin

    a[0]:=a[i];

    a[i]:=a[j];

    a[j]:=a[0];

    inc(i);

    dec(j);

    end;until i>j;

    if lif iend;

    beginfor n:=1 to 10 do read(a[n]);

    qsort(1,10);

    for n:=1 to 10 do write(a[n]:4);

    end.

  9. Anonymous users2024-02-02

    Do you think it's a comparison of pascal's own strings? Upstairs is completely out of line!! For fast arrangement, it seems that there is none, at least the result should be under o(n 3) (you can use bubbles, it should be the easiest, because the string is too long, you can't convert the 26 base to a decimal integer, and you can only keep comparing it with two adjacent string code shirts, and then swap it, you can also use the n keyword to sort, and turn the letters of each bit into an array of integers:

    array[1..length(st),1..n] of shortint;It's OK and then sort each bit in turn、、But it is recommended to use bubbling,Because the program that is quickly arranged is very long,It is also very troublesome to Zen the excellent model、、

  10. Anonymous users2024-02-01

    Generally, the third item is used.

    1.Cyclic byte-by-byte comparison (using fast rowing).

    2 Conversion to 26 decimal number comparison.

    3 Quick Row Direct Comparison (A String > B String) then A Dictionary Order B (Example:'aa'<'ab','aa'<'db','The order in the dictionary in question A is generally calculated by algorithm, and there is no special sorting problem;

  11. Anonymous users2024-01-31

    In the same way, convert to Asker code and fast row to character.

Related questions
12 answers2024-05-17

Sort command;

The main keyword "select" Grades (or column B), "Descending"; >>>More

11 answers2024-05-17

It's the machine code of the phone.

10 answers2024-05-17

The surname of the hundred families was written in the Song Dynasty, because the emperor of the Song Dynasty was surnamed Zhao, so Zhao was written in the first place. The other surnames are not ranked by power or number, but are pronounced smoothly. The end of the old hundred family name is the end of the hundred family name.