23,121
社区成员
发帖
与我相关
我的任务
分享
Generated at --- Fri Dec 26 16:59:54 CST 2008
The earliest day of June,18th is your choice to invite the most classmates in Shanhai!
They are: Long Zhang Dai
Fan 0 0 1
Gong 0 1 0
Tian 0 1 1
Long 1 0 0
Zhang 1 0 1
Dai 1 1 0
Jin 1 1 1
BEGIN {
# RS = ";"
# FS = ")"
printf (" Generated at --- ")
system("date")
printf (" ");
max = 0
date = 2;
}
{#get date and initial total
if ($0 ~ /Name/)
for(x=2; x<=NF; x++) {
total[x, 2] = "They are: "
total[x, 1] = 0 #number of ava members
total[x, 0] = $x #invitation date
}
}
{ if($0 ~ /Jin/) next } #ignore host Mr.Jin
{
for ( x = 2; x <= NF; x++)
if($x == 1) {
total[x, 1] = total[x, 1] + 1
total[x, 2] = sprintf("%s %s",total[x, 2], $1)
#printf ("total[%d] = %d ",x,total[x,1])
if(total[x, 1] > max) {
date = x;
max = total[x, 1]
}
else if ((total[x, 1] == max) && (date > x))
date = x
}
}
END {
#print max, date
if(max == 0)
print "Disappointed result: I am afraid that King's second invitation is to be canceled again! "
else {
print "The earliest day of June,18th is your choice to invite the most classmates in Shanhai!"
print total[date, 2]
}
}
awk -f 1.awk 1.txt