题解

136 条题解

  • -1
    @ 2014-08-03 16:24:13

    第2次才对 ::>_<::

    记录信息
    评测状态 Accepted
    题目 P1257 水王争霸
    递交时间 2014-08-03 16:22:47
    代码语言 C++
    评测机 VijosEx
    消耗时间 15 ms
    消耗内存 392 KiB
    评测时间 2014-08-03 16:22:52
    评测结果
    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 360 KiB, score = 5
    测试数据 #1: Accepted, time = 0 ms, mem = 352 KiB, score = 15
    测试数据 #2: Accepted, time = 15 ms, mem = 360 KiB, score = 20
    测试数据 #3: Accepted, time = 0 ms, mem = 388 KiB, score = 25
    测试数据 #4: Accepted, time = 0 ms, mem = 392 KiB, score = 35
    Accepted, time = 15 ms, mem = 392 KiB, score = 100

  • -1
    @ 2014-07-21 19:01:12

    #include<cstdio>
    #include<deque>
    #include<algorithm>
    #include<cstring>
    #define IOFileName "P1257"
    using namespace std;
    const int maxscorelen=10001;
    struct king{
    char name[20];
    char score[maxscorelen];
    }tmp;
    deque<king>d;
    int n;
    bool cmp(king a,king b){
    unsigned int lena=strlen(a.score),lenb=strlen(b.score);
    if(lena!=lenb)
    return lena>lenb;
    else{
    unsigned int p=0;
    while(p<lena&&p<lenb){
    if(a.score[p]!=b.score[p])
    return a.score[p]>b.score[p];
    p++;
    }
    p=0;
    lena=strlen(a.name);lenb=strlen(b.name);
    while(p<lena||p<lenb){
    if(a.name[p]!=b.name[p])
    return a.name[p]<b.name[p];
    p++;
    }
    }
    }
    int main(){
    //freopen(IOFileName".in","r",stdin);
    //freopen(IOFileName".out","w",stdout);
    scanf("%d\n",&n);
    for(int i=0;i<n;i++){
    scanf("%s\n%s\n",tmp.name,tmp.score);
    d.push_back(tmp);
    }
    sort(d.begin(),d.end(),cmp);
    for(int i=0;i<n;i++)
    printf("%s\n",d[i].name);
    }
    22MS+668KB

    • @ 2014-08-15 16:07:13

      #include<iostream>
      #include<deque>
      #include<string>
      #include<algorithm>
      using namespace std;
      int n;
      struct king{string id;string ft;}tmp;
      deque<king>d;
      bool cmp(const king a,const king b){
      if(a.ft.length()!=b.ft.length()){return a.ft.length()>b.ft.length();}
      else{
      if(a.ft!=b.ft){return a.ft>b.ft;}
      else{return a.id<b.id;}
      }
      }
      int main(){
      cin>>n;
      for(int i=0;i<n;i++){
      cin>>tmp.id;
      cin>>tmp.ft;
      d.push_back(tmp);
      }
      sort(d.begin(),d.end(),cmp);
      for(unsigned int i=0;i<d.size();i++){cout<<d[i].id<<endl;}
      }
      15ms+272KiB

  • -1
    @ 2013-11-02 16:44:30

    type shui=record
    na,num:ansistring;
    len:longint;
    end;
    var a:array[1..1000]of shui;
    i,j,k,l,m,n:longint;
    c,d:string;
    begin
    readln(n);
    for i:=1 to n do
    begin
    readln(a[i].na);
    readln(a[i].num);
    a[i].len:=length(a[i].num);
    end;
    for i:=1 to n do
    begin
    for j:=1 to n do
    if a[j].len>k then
    begin
    k:=a[j].len; c:=a[j].num; l:=j; d:=a[j].na;
    end
    else
    if (a[j].len=k) and (a[j].num>c) then
    begin
    c:=a[j].num; k:=a[j].len; l:=j; d:=a[j].na;
    end
    else
    if (a[j].len=k) and (a[j].num=c) and (a[j].na<d) then
    begin
    c:=a[j].num; k:=a[j].len; l:=j; d:=a[j].na;
    end;
    writeln(d);
    a[l].len:=0;
    c:='';
    k:=0;
    d:='';
    end;

    end.

  • -1
    @ 2013-11-02 16:44:16

    不用排序。。

  • -1
    @ 2013-11-02 16:43:56

    评测结果
    编译成功

    foo.pas(19,17) Warning: Variable "k" does not seem to be initialized

    测试数据 #0: Accepted, time = 0 ms, mem = 904 KiB, score = 5

    测试数据 #1: Accepted, time = 0 ms, mem = 908 KiB, score = 15

    测试数据 #2: Accepted, time = 0 ms, mem = 908 KiB, score = 20

    测试数据 #3: Accepted, time = 0 ms, mem = 908 KiB, score = 25

    测试数据 #4: Accepted, time = 15 ms, mem = 908 KiB, score = 35

    Accepted, time = 15 ms, mem = 908 KiB, score = 100

    过了!!!

  • -1
    @ 2013-04-25 20:01:35

    卧槽= =这道题真的是快排WA两遍,冒泡一遍过T_T。

  • -1
    @ 2012-11-08 14:37:53

    此题测试编写的各种排序是否正确 (快排,堆排,冒泡,插排)ETC

  • -1
    @ 2012-11-06 13:44:09

    var

    i,j,n:longint;

    a:array[0..1001,0..2] of string;

    procedure jiaohuang(i,j:longint);

    begin

    a[0,0]:=a;

    a:=a[j,2];

    a[j,2]:=a[0,0];

    a[0,0]:=a;

    a:=a[j,1];

    a[j,1]:=a[0,0];

    end;

    procedure max(x,y:longint);

    var

    i:longint;

    begin

    if length(a[x,2])length(a[y,2]) then exit else

    begin

    for i:=1 to length(a[x,2]) do begin

    if a[x,2,i]a[y,2,i] then exit;

    end;

    end;

    end;

    begin

    readln(n);

    for i:=1 to n do begin

    readln(a);

    readln(a);

    end;

    for i:=1 to n-1 do begin

    for j:=i+1 to n do begin

    max(i,j);

    end;

    end;

    for i:=1 to n do writeln(a);

    end.

    大虾帮忙看看吧、只对第一个点...

  • -1
    @ 2012-10-03 19:40:22

    庆祝自己AC30和提交100(我的AC率实在是太差了……)

  • -1
    @ 2012-09-27 10:07:38

    无语了,看了测试用例一个一个比都是对的,提交却是错的。

  • -1
    @ 2010-04-16 18:58:45

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    var i,j,n:longint;fts:packed array[1..100000] of ansistring;

    id:packed array[1..100000] of string;t:ansistring;x:string;

    begin

    readln(n);for i:=1 to n do begin readln(id[i]);readln(fts[i]);end;

    for i:=1 to n-1 do

    for j:=i+1 to n do

    if(length(fts[j])>length(fts[i]))or((length(fts[j])=length(fts[i]))and(fts[i]id[j]))then begin t:=fts[i];fts[i]:=fts[j];fts[j]:=t;x:=id[i];id[i]:=id[j];id[j]:=x;end;

    for i:=1 to n do writeln(id[i]);

    end.

  • -1
    @ 2010-04-02 16:44:08

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    VAR

    A:ARRAY[1..1001]OF STRING[21];

    B:ARRAY[1..1001]OF ANSISTRING;

    I,J,N:LONGINT;

    TEMS:STRING;

    TEMP:ANSISTRING;

    BEGIN

    READLN(N);

    FOR I:=1 TO N DO

    BEGIN

    READLN(A);

    READLN(B);

    END;

    FOR I:=1 TO N-1 DO

    FOR J:=I+1 TO N DO

    IF ((LENGTH(B)

  • -1
    @ 2010-04-01 16:51:33

    var

    n,i,j,temp:integer;

    name:array[1..1000] of string;

    nametemp:string;

    m:array[1..1000] of ansistring;

    mtemp:ansistring;

    c:array[1..1000] of integer;

    d:array[1..1000] of integer;

    procedure chang(i,j:integer);

    begin

    nametemp:=name[i]; name[i]:=name[j]; name[j]:=nametemp;

    mtemp:=m[i]; m[i]:=m[j]; m[j]:=mtemp;

    temp:=c[i]; c[i]:=c[j]; c[j]:=temp;

    end;

    begin

    readln(n);

    for i:=1 to n do

    begin

    readln(name[i]);

    readln(m[i]);

    c[i]:=length(m[i]);

    end;

    for i:=1 to n-1 do

    for j:=i+1 to n do

    if (c[i]

  • -1
    @ 2010-03-18 23:16:34

    没想到冒泡也可以

  • -1
    @ 2009-11-09 18:46:15

    快拍时while的条件真是多呀,一不小心就写错

    后来变了个布尔函数,就清楚了多

    另外谢谢guori12321

    直接比较确实不用在编个函数,挺方便的

    program p1257;

    type x=record

    sw:string;

    ts:ansistring;

    end;

    var a:array[1..2000] of x;

    n:longint;

    procedure init;

    var i:longint;

    begin

    readln(n);

    for i:=1 to n do

    begin

    readln(a[i].sw);

    readln(a[i].ts);

    end;

    end;

    procedure sweap(i,j:longint);

    var tmp:string;

    begin

    tmp:=a[i].sw; a[i].sw:=a[j].sw; a[j].sw:=tmp;

    tmp:=a[i].ts; a[i].ts:=a[j].ts; a[j].ts:=tmp;

    end;

    {function max(str1,str2:ansistring):byte;

    var i:longint;

    begin

    i:=1;

    while (str1[i]=str2[i]) and (iord(str2[i]) then exit(1)

    else if ord(str1[i])length(strts2) then exit(true)

    else if length(strts1)=length(strts2) then

    begin

    if strts1>strts2 then exit(true)

    else if strts1=strts2 then begin

    if not(strsw1>strsw2) then exit(true)

    end

    end;

    exit(false);

    end;

    procedure qsort(l,r:longint);

    var i,j,t:longint;

    strsw,strts:string;

    begin

    i:=l; j:=r; strts:=a[i].ts; t:=length(strts); strsw:=a[i].sw;

    repeat

    while (ok(a[j].ts,a[j].sw,strts,strsw)) and (j>i) do dec(j);

    if a[i].swa[j].sw then sweap(i,j);

    while (ok(strts,strsw,a[i].ts,a[i].sw)) and (j>i) do inc(i);

    if a[i].swa[j].sw then sweap(i,j);

    until i=j;

    a[i].sw:=strsw; a[i].ts:=strts;

    dec(i); inc(j);

    if l

  • -1
    @ 2009-11-06 22:37:08

    一年之后……终于AC&……

  • -1
    @ 2009-11-03 13:50:15

    快排什么的最讨厌了,冒泡就能过。

  • -1
    @ 2009-11-01 21:40:01

    话说PAS中就有字符串比较的功能。但是注意,它是逐位比较ASCII的大小,并不比较长度,所以之前要判断一下长度,相等了才能用它来比较数字的串。还有,比较字母的时候,因为是ASCII,所以有'a'>'b' 是false的情况,所以要加一个not.

  • -1
    @ 2009-10-30 19:44:49

    琐题。。。 我忘记写ansistring都过了。。

  • -1
    @ 2009-10-23 20:18:30

    ar

    n,i,j:longint;

    a:array[0..1001] of string;

    b:array[0..1001] of ansistring;

    temp:ansistring;

    temp1:string;

    begin

    readln(n);

    for i:= 1 to n do

    begin

    readln(a[i]);

    readln(b[i]);

    // writeln(length(b[i]));

    end;

    for i:= 1 to n-1 do

    begin

    for j:=i+1 to n do

    begin

    if ( length(b[i])

信息

ID
1257
难度
6
分类
其他 | 排序 点击显示
标签
(无)
递交数
4117
已通过
1161
通过率
28%
被复制
3
上传者