fork download
  1. #include <stdio.h>//2022年の過去問問5
  2.  
  3. int main() {
  4. int ten[10],i,j,count1,count2,max1,max2,min1,min2;
  5. for(i=0;i<10;i++)
  6. {
  7. scanf("%d",&ten[i]);
  8. }
  9. for(i=0;i<10;i++)
  10. {
  11. count1=10;
  12. count2=10;
  13. for(j=0;j<10;j++)
  14. {
  15. if(ten[i]>ten[j]) count1--;
  16. else if(ten[i]<ten[j]) count2--;
  17. }
  18. if(count1==1) max1=i+1;
  19. else if(count1==2) max2=ten[i];
  20. else if(count2==1) min1=i+1;
  21. else if(count2==2) min2=ten[i];
  22. }
  23. printf("%d\n",max1);
  24. printf("%d\n",max2);
  25. printf("%d\n",min1);
  26. printf("%d\n",min2);
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0s 5320KB
stdin
33 52 80 98 76 56 87 43 90 66
stdout
4
90
1
43