Advertisement
Robert_JR

SJF

Dec 14th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.38 KB | None | 0 0
  1. echo "Enter how many process you have :"
  2. read n
  3. echo "Enter precess , AT , BT respectively"
  4. for((i=1;i<=n;i++))
  5. do
  6.     read p[$i];
  7.     read at[$i];
  8.     read bt[$i];
  9. done
  10.  
  11. for((i=1;i<=n-1;i++))
  12. do
  13.     for((j=1;j<=n-1;j++))
  14.     do
  15.         if [ ${at[$j]} -gt ${at[$j+1]} ]
  16.         then
  17.             temp=${at[$j]}
  18.             at[$j]=${at[$j+1]}
  19.             at[$j+1]=$temp
  20.            
  21.             temp=${bt[$j]}
  22.             bt[$j]=${bt[$j+1]}
  23.             bt[$j+1]=$temp
  24.            
  25.             temp=${p[$j]}
  26.             p[$j]=${p[$j+1]}
  27.             p[$j+1]=$temp
  28.         fi
  29.     done
  30. done
  31.  
  32. ct=`expr ${at[1]} + ${bt[1]} `
  33. tat=`expr $ct - ${at[1]} `
  34. wt[1]=`expr $tat - ${bt[1]} `
  35.  
  36. for((i=2;i<=n-1;i++))
  37. do
  38.         for((j=2;j<=n-1;j++))
  39.         do
  40.             if [ ${bt[$j]} -gt ${bt[$j+1]} ]
  41.             then
  42.                 temp=${at[$j]}
  43.                 at[$j]=${at[$j+1]}
  44.                 at[$j+1]=$temp
  45.        
  46.                 temp=${bt[$j]}
  47.                 bt[$j]=${bt[$j+1]}
  48.                 bt[$j+1]=$temp
  49.        
  50.                 temp=${p[$j]}
  51.                 p[$j]=${p[$j+1]}
  52.                 p[$j+1]=$temp
  53.             fi
  54.         done
  55. done
  56.  
  57. for((i=2;i<=n;i++))
  58. do
  59.     ct=`expr $ct + ${bt[$i]} `
  60.     tat=`expr $ct - ${at[$i]} `
  61.     wt[i]=`expr $tat - ${bt[$i]} `
  62. done
  63.  
  64. twt=0
  65. echo ${wt[*]}
  66.  
  67. for((i=1;i<=n;i++))
  68. do
  69.     twt=`expr $twt + ${wt[i]} `
  70. done
  71. echo $twt
  72.  
  73. awt=`expr $twt / $n `
  74.  
  75. echo $awt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement