+ 4

I want a algorithm for finding the ranks of the numbers

if I have taken 5 numbers 20 10 30 20 50 then the output should be 20. 3 10. 4 30. 2 20. 3 50. 1 this is the problem plz help

15th May 2017, 6:38 AM
manish agnani
manish agnani - avatar
21 odpowiedzi
+ 8
int array[10]; for(int i=0;i<10 ;i++){ cin>>0array[i]; } for(int x=10;x>=0;x--){ cout<<x<<". "<<array[x] } return 0
15th May 2017, 6:56 AM
Umbe
Umbe - avatar
+ 8
OK i didn' t understand the question. dammat i didn" t read correctly. you can just put an if in the for
15th May 2017, 7:06 AM
Umbe
Umbe - avatar
+ 8
i LL say you what does it take. I am busy until 18.00
15th May 2017, 7:23 AM
Umbe
Umbe - avatar
+ 8
ah lol just put a new array to compare and an if at the end
16th May 2017, 4:52 AM
Umbe
Umbe - avatar
+ 7
ooh come on this is not so hard
15th May 2017, 7:11 AM
Umbe
Umbe - avatar
+ 7
it is way easier https://code.sololearn.com/c2FyHF7at2Yc/?ref=app edit: nope i m wrong i will correct it later
16th May 2017, 7:32 AM
Umbe
Umbe - avatar
+ 6
https://code.sololearn.com/c04T3J2R5J0s/?ref=app It is a good training. Thanks for the inspiration :D
15th May 2017, 8:43 PM
Umbe
Umbe - avatar
+ 4
You can use any of the sorting problems like insertion sort,merge sort, bubble sort, heap sort.... And for each time in the loop print the value of the loop counter(gives you the index). Start the for loop from n( size of the input array) and then decrement it till it becomes negative. That's it Bro. cool..
15th May 2017, 6:51 AM
Vishnu ks
Vishnu ks - avatar
+ 4
If the values are same then their ranks will be same.
15th May 2017, 6:55 AM
Vishnu ks
Vishnu ks - avatar
+ 4
right one manish
15th May 2017, 7:03 AM
Vishnu ks
Vishnu ks - avatar
+ 3
@umbe You are not at all sorting them. You are just printing the numbers in the reverse order....
15th May 2017, 6:58 AM
Vishnu ks
Vishnu ks - avatar
+ 3
it's ok, this one is a really tough problem @umbe
15th May 2017, 7:09 AM
manish agnani
manish agnani - avatar
+ 3
This is not that hard as of moving mount everest.
15th May 2017, 7:12 AM
Vishnu ks
Vishnu ks - avatar
+ 2
bro it does not work if there are same number present, like 20 & 20 in given example the output by your method is 20. 3 10. _5 30. 2 20. 3 50. 1
15th May 2017, 6:54 AM
manish agnani
manish agnani - avatar
+ 2
ya but the ranks after the same rank is not correct
15th May 2017, 6:58 AM
manish agnani
manish agnani - avatar
+ 2
@umbe is that some kind of joke 😂😂😂😂😂😂
15th May 2017, 6:59 AM
manish agnani
manish agnani - avatar
+ 2
try it bro you will understand @umbe
15th May 2017, 7:11 AM
manish agnani
manish agnani - avatar
+ 2
ya I said it is tough not impossible and on the second hand it is a very exciting problem you get to learn a lot
15th May 2017, 7:13 AM
manish agnani
manish agnani - avatar
+ 2
ok @umbe
15th May 2017, 7:25 AM
manish agnani
manish agnani - avatar
+ 1
no bro @umbe the sequence of number should not be changed and there is no same rank for 2 same numbers. still nice try 🤗🤘
16th May 2017, 3:08 AM
manish agnani
manish agnani - avatar