1 条题解

  • 0
    @ 2023-3-13 12:11:08

    C++ :

    #include <bits/stdc++.h> 
    using namespace std;
    string s[1005]; 
    int n;
    int main(){
    	while(cin>>s[n])
    	{
    		if(s[n]=="end")break;
    		n++;
    	}
    	string t;
    	for(int i=0;i<n;i++)
    		for(int j=n-1;j>i;j--)
    			if(s[j]<s[j-1])
    			{
    				t=s[j];
    				s[j]=s[j-1];
    				s[j-1]=t;
    			}
    	for(int i=0;i<n;i++)
    		cout<<s[i]<<endl;
    	return 0;
    }
    

    Pascal :

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

    信息

    ID
    2071
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者