zoukankan      html  css  js  c++  java
  • 铺地毯pascal程序

    题意

    找出最后一张覆盖在点上的地毯编号


    分析

    先输入,再从后面找,这样会更快


    var
    n,i,j:longint;
    a:array[0..20]of string;
    b,l:array[0..20]of longint;
    begin
        readln(n);
        for i:=1 to n do
        begin
            readln(a[i]);
            l[i]:=length(a[i]);
            b[i]:=i;
        end;


        for i:=1 to n-1 do
        begin


            for j:=i+1 to n do
            begin
                if (l[i]<l[j])or(l[i]=l[j])and(a[i]<a[j]) then
                begin
                    a[0]:=a[i];a[i]:=a[j];a[j]:=a[0];
                    l[0]:=l[i];l[i]:=l[j];l[j]:=l[0];
                    b[0]:=b[i];b[i]:=b[j];b[j]:=b[0];
                end;
            end;


        end;
        writeln(b[1]);
        write(a[1]);
    end.

  • 相关阅读:
    数据结构实验之栈四:括号匹配
    数据结构实验之栈三:后缀式求值
    8月7日学习
    8月6日学习
    8月5日学习
    8月4日学习
    周总结
    8月3日学习
    8月2日学习
    8月1日学习
  • 原文地址:https://www.cnblogs.com/YYC-0304/p/9500223.html
Copyright © 2011-2022 走看看