fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. double getRank(int scores[], int newscore, int maxlen) {
  5.  
  6. int scoresLength = sizeof(scores)/sizeof(scores[0]);
  7. int i;
  8. for(i=0;i<scoresLength;i++){
  9. if( newscore > scores[i]){
  10. return i+1;
  11. }else{
  12. if(newscore = scores[i]){
  13. if(i < maxlen-1)
  14. return i+1;
  15. }
  16. }
  17. }
  18. return -1;
  19.  
  20. }
  21.  
  22. int main() {
  23.  
  24. // your code goes here
  25.  
  26. int scores[51]={ 66, 54, 23, 12 };
  27. int newscore;
  28. int maxlen;
  29.  
  30. newscore = 45;
  31. maxlen=51;
  32.  
  33. printf("%d\n", getRank(scores, newscore, maxlen));
  34. return 0;
  35. }
  36.  
  37.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
-1841731672