1. //Assignment 4
  2. //Kyle Weeks
  3. //3/17/11
  4.  
  5. #include <stdio.h>
  6. #include <math.h>
  7.  
  8. int main(){
  9. //Load point
  10. FILE *ifp;
  11. //open file
  12. ifp = fopen("/Users/kylew/Documents/example/ucfidol2.txt", "r");
  13. //variables
  14. int con, judg, shows, dev, k=0, j=0, c=0;
  15. fscanf(ifp, "%d", &shows);
  16. //Loop all the shows
  17. for (k=0; k<shows; k++) {
  18. fscanf(ifp, "%d%d%d", &con, &judg, &dev);
  19. int sum[shows][con][judg];
  20. int badjud[judg];
  21. int corp=0, honjud = judg, win=0;
  22. double bestavg=0;
  23. double avga[con], sdev[judg], avgj[judg];
  24. avgj[0]=0.0;
  25. avga[0]=0.0;
  26. sdev[0]=0.0;
  27. badjud[0]=0;
  28. //Loop all the contestants
  29. for (c=0; c<con; c++) {
  30. //Loop all the judges
  31. for (j=0; j<judg; j++) {
  32. //add up all the judges scores
  33. fscanf(ifp, "%d", &sum[k][c][j]);
  34. avga[c] = avga[c] + sum[k][c][j];
  35. avgj[j] = avgj[j] + sum[k][c][j];
  36. }
  37. avga[c]=avga[c]/judg;
  38. }
  39. for (j=0; j<judg; j++) {
  40. avgj[j] = avgj[j] / con;
  41. }
  42.  
  43. for (j=0; j<judg; j++) {
  44.  
  45. for (c=0; c<con; c++) {
  46. sdev[j]=sdev[j]+pow(avgj[j] - sum[k][c][j], 2);
  47. }
  48. sdev[j] = sdev[j] / con;
  49. sdev[j] = sqrt(sdev[j]);
  50. //printf("%lf\n",sdev[j]);
  51.  
  52. }
  53. for (j=0; j<judg;j++){
  54. if (sdev[j] > dev) {
  55. corp = corp + 1;
  56. printf("true %lf,\n", sdev[j]);
  57. }
  58. }
  59. if (corp < judg) {
  60. for (c=0; c <con; c++) {
  61. for (j=0; j<judg; j++) {
  62. if (sdev[j] > dev) {
  63. avga[c] = avga[c] * honjud;
  64. //printf("%.2lf \n",avga[c]);
  65. avga[c] = avga[c] - sum[k][c][j];
  66. //printf("%.2lf \n",avga[c]);
  67. honjud = honjud - 1;
  68. avga[c] = avga[c] / honjud;
  69. //printf("%.2lf \n",avga[c]);
  70. }
  71. }
  72. honjud = judg;
  73. if (avga[c] > bestavg){
  74. bestavg = avga[c];
  75. win = c + 1;
  76.  
  77. }
  78.  
  79. }
  80. }
  81. else {
  82. for(c=0; c<con;c++) {
  83. if (avga[c] > bestavg) {
  84. bestavg = avga[c];
  85. win = c + 1;
  86. }
  87. }
  88. }
  89. printf("\nUCF IDOL SHOW #%d \n",k+1);
  90. printf("Contestant #%d, you win with an average score of %.2lf \n",win,bestavg);
  91. for (j=0; j<judg; j++) {
  92. if (sdev[j]>dev){
  93. badjud[j]=j+1;
  94. printf("%d,", badjud[j]);
  95. }
  96. else{
  97. printf(" ");
  98. }
  99. }
  100. }
  101. fclose(ifp);
  102. return 0;
  103.  
  104. }
  105.