1 solutions

  • 0
    @ 2024-12-10 23:39:22

    C++ :

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <iostream>
    #include <cmath>
    #include <cstdlib>
    using namespace std;
    struct node
    {
       char a[1100];
    };
    node b[1100];
    char v[1100];
    bool Cmp(node x,node y)
    {
        if(strcmp(x.a,y.a)<=0) return true;
        else return false;
    }
    int main()
    {
        int i,j,s;
        s=0;
        while(gets(v))
        {
            s++;
            strcpy(b[s].a,v);
        }
        sort(b+1,b+s+1,Cmp);
        for(i=1;i<=s;i++)
        {
            printf("%s\n",b[i].a);
        }
        return 0;
    }
    
    

    Pascal :

    var a:array[1..100] of string[100]; 
        i,j,n:integer; 
        s:string[100]; 
    begin
      n:=0; 
      readln(s); 
      while s<>'' do
       begin
        inc(n); 
        a[n]:=s; 
        readln(s); 
       end; 
      for i:=1 to n-1 do
       for j:=i+1 to n do
        if a[i]>a[j] then
         begin
           s:=a[i]; 
           a[i]:=a[j]; 
           a[j]:=s; 
         end; 
      for i:=1 to n do
       writeln(a[i]); 
    end. 
    
    
    • 1

    Information

    ID
    619
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    10
    Tags
    # Submissions
    2
    Accepted
    1
    Uploaded By