10.18 文件名排序 2433

来源:互联网 发布:linux提权 编辑:程序博客网 时间:2024/06/07 03:30

  • 题目
  • 题解
  • 代码

题目

这里写图片描述

题解

冒泡然后判断就好了,判断要有条理、细心、全面

代码

var  n,i,j:longint;  c:string;  a,b:array[0..100]of longint;  s,t:array[1..100]of string;procedure swap(var a,b:longint);var  c:longint;begin  c:=a;a:=b;b:=c;end;begin  readln(n);  for i:=1 to n do    begin      readln(c);      s[i]:=c;a[i]:=i;      if pos('.',c)>0 then      begin        s[i]:=copy(c,1,pos('.',c)-1);        delete(c,1,pos('.',c));        t[i]:=c;      end;    end;  for i:=1 to n do    for j:=i+1 to n do      begin        if (length(t[a[i]])=0)and(length(t[a[j]])>0)and(s[a[i]]>s[a[j]]) then swap(a[i],a[j]) else        if (length(t[a[i]])=0)and(length(t[a[j]])>0) then swap(a[i],a[j]) else        if (t[a[i]]=t[a[j]])and(s[a[i]]>s[a[j]]) then swap(a[i],a[j]) else        if (length(t[a[i]])>0)and(length(t[a[j]])>0)and(t[a[i]]>t[a[j]]) then swap(a[i],a[j]) else        if (length(t[a[i]])>0)and(length(t[a[j]])>0)and(t[a[i]]=t[a[j]])and(s[a[i]]>s[a[j]]) then swap(a[i],a[j]);      end;  for i:=1 to n do    b[a[i]]:=i;  for i:=1 to n do    writeln(b[i]);end.
原创粉丝点击