足球联赛
2015-11-01 14:16
267 查看
思路:极简单的一题。先读入,再计算每队得分。快排一次找出得分最多的队伍,再把队伍按从小到大输出即可。
其实不快排也可以,
program t1; type paiming=record xh,fs:longint; end; var n,i,j:longint; s:array[1..50,1..50]of char; a:array[1..50]of paiming; procedure sort(l,r: longint); var i,j,x: longint; y:paiming; begin i:=l; j:=r; x:=a[(l+r) div 2].fs; repeat while a[i].fs>x do inc(i); while x>a[j].fs do dec(j); if not(i>j) then begin y:=a[i]; a[i]:=a[j]; a[j]:=y; inc(i); j:=j-1; end; until i>j; if l<j then sort(l,j); if i<r then sort(i,r); end; procedure kp(l,r: longint); var i,j,x: longint; y:paiming; begin i:=l; j:=r; x:=a[(l+r) div 2].xh; repeat while a[i].xh<x do inc(i); while x<a[j].xh do dec(j); if not(i>j) then begin y:=a[i]; a[i]:=a[j]; a[j]:=y; inc(i); j:=j-1; end; until i>j; if l<j then kp(l,j); if i<r then kp(i,r); end; procedure open; begin assign(input,'soccer.in'); assign(output,'soccer.out'); reset(input); rewrite(output); end; procedure guanbi; begin close(input); close(output); end; begin open; readln(n); for i:=1 to n do a[i].xh:=i; for i:=1 to n do a[i].fs:=0; for i:=1 to n do begin for j:=1 to n do read(s[i,j]); readln; end; for i:=1 to n do for j:=1 to n do begin if s[i,j]='W' then inc(a[i].fs,3); if s[i,j]='D' then begin inc(a[i].fs); inc(a[j].fs); end; if s[i,j]='L' then inc(a[j].fs,3); end; sort(1,n); for i:=1 to n do if a[i].fs<>a[i+1].fs then begin if i=1 then writeln(a[i].xh) else begin kp(1,i); for j:=1 to i do write(a[j].xh,' '); writeln; end; break; end; //for i:=1 to n do writeln(a[i].xh,' ',a[i].fs,' '); guanbi; end.
相关文章推荐
- LeetCode Implement Stack using Queues (数据结构)
- Git学习笔记(一)
- 计数排序
- jsp传值问题
- cookie、session 区别
- 上传 Applestore 应用所需要的素材
- R中的绘图知识整理
- Debian8安装
- uva 11491——Erasing and Winning
- POJ 1947 Rebuilding Roads(树形DP)
- CentOS 6.5下安装MySQL 5.6.21
- 文件的结构
- 在博客园落户
- ./configure,make,make install的作用
- UC浏览器无法打开百度网盘
- 对TCP性能的考虑
- JavaScript调用传递变量参数的相关问题及解决办法
- No.5 Single Number 找出一组数中落单的数
- Sum Root to Leaf Numbers
- ZOJ3623 Battle Ships