shell practice --PAT title: 1004 standings! (Failures)

Reads  the n-( >) student's name, school, achievement, output the highest score and the lowest score the student's name and student number.

Input formats:

Each test comprises a test input format

第 1 行:正整数 n
第 2 行:第 1 个学生的姓名 学号 成绩
第 3 行:第 2 个学生的姓名 学号 成绩
  ... ... ...
第 n+1 行:第 n 个学生的姓名 学号 成绩

Wherein 姓名and 学号are no more than 10 characters in the string, the result is an integer between 0 and 100, where a set of test cases to ensure that no two are the same student achievement.

Output formats:

For each test case output 2, line 1 is the highest score a student's name and student number, the second line is the lowest score the student's name and student number, there is a space between the strings.

Sample input:

3
Joe Math990112 89
Mike CS991301 100
Mary EE990830 95

Sample output:

Mike CS991301
Joe Math990112

Analysis:
  1. assessment should be the bubble sort, bubble sort through to get the maximum and minimum scores. It may also examine two-dimensional array of related concepts.
  2. The range of problems, the need to determine the length of the length
# / bin / the bash 
ARR = ( 'Joe Math990112 89' 'Mike CS991301 100' 'Mary EE990830 95') 
compare_score () { 
        IF [$ $ -LT-TEMP max]; the then    
                max = $ TEMP 
        Fi 
        IF [$ min -gt $ TEMP]; the then 
                min = $ TEMP 
        Fi 
} 

max = 0 # to an initial value, here directly specified, may be extracted from inside the array a value 
min = 100 

for I in "$ {ARR [@]}" 
do 
        arr2 is = ($ I) 
        name = $ {arr2 is [0]} 
        NUM = $ {arr2 is [. 1]} 
        Score = $ {arr2 is [2]} 
        TEMP = $ Score 
        compare_score 
DONE 
for J in "$ {ARR [@]}" 
do  
        str1 = $ (echo $ J | grep $ {max} | awk '{$. 1 Print ""$2}')
        str2 = $ (echo $ J | grep min {} $ | awk '{$. 1 Print ""$2}')
        if [ -n "$str1" ]
        then 
                max_str=$str1
        elif [ -n "$str2" ]
        then
                min_str=$str2
        fi
done
echo $max_str
echo $min_str

  Obviously, this is not over, the features are not realized.

Guess you like

Origin www.cnblogs.com/wyf-349/p/11237119.html