|
发表于 2009-10-16 03:53:57
|
显示全部楼层
用“指针”的思想,插入数据时不用移动。--好像叫“链表”
姓一样时比名。- #!/usr/bin/awk -f
- BEGIN{FS=":"
- print "\n"
- print "\t\t***CAMPAIGN 1998 CONTRIBUTIONS***"
- print "---------------------------------------------------------"
- print "NAME\tPHONE\t\tJAN | FEB | MAR | Total Donated"
- print "---------------------------------------------------------"
- hight = 0
- lowest = 10000
- ht = 0
- user = $1
- [color="Red"]over500[0,0]=0[/color]
- }
- {$6 = $3+$4+$5;print $1"\t"$2"\t"$3"\t"$4"\t"$5"\t"$6}
- {total+=$6;average=total/12}
- {if($5 > hight) hight = $5}
- {if($3 < lowest) lowest = $3}
- {if($6 > ht) {ht = $6;user = $1}}
- [color="Red"]$6 > 500{split($1,name," ");
- for(p=0; over500[p,0] != 0 && (name[2] > over500[over500[p,0],2] || name[2] == over500[over500[p,0],2] && name[1] > over500[over500[p,0],3]); p=over500[p,0]);
- over500[$0,0]=over500[p,0];
- over500[$0,1]=$1"--"$2;
- over500[$0,2]=name[2];
- over500[$0,3]=name[1];
- over500[p,0]=$0;
- }[/color]
- END{
- print "---------------------------------------------------------"
- print "\t\tSUMARY"
- print "---------------------------------------------------------"
- printf "The campaign received a total of $" "%2.2f\n",total" for this quarter\."
- printf "The average donation for the 12 contributors was $" "%2.2f\n",average"\."
- print "The highest contribution was $"hight"."
- print "The lowest contribution was $"lowest"."
- print "The highest total contribution was $" ht " made by "user"."
- print " ***THANKS " user" ***"
- print "The following people donated over $500 to the campaign."
- print "They are eligible for the quarterly drawing!!"
- print "Listed are their names (sorted by last names) and phone numbers:"
- [color="Red"]for (p=over500[0,0];p != 0; p=over500[p,0]) print over500[p,1]
- }[/color]
复制代码 |
|