kavetiraviteja1992
BAN USERAlgorithm
I) Traverse the given number from rightmost digit, keep traversing till you find a digit which is smaller than the previously traversed digit. For example, if the input number is “534976”, we stop at 4 because 4 is smaller than next digit 9. If we do not find such a digit, then output is “Not Possible”.
II) Now search the right side of above found digit ‘d’ for the smallest digit greater than ‘d’. For “534976″, the right side of 4 contains “976”. The smallest digit greater than 4 is 6.
III) Swap the above found two digits, we get 536974 in above example.
IV) Now sort all digits from position next to ‘d’ to the end of number. The number that we get after sorting is the output. For above example, we sort digits in bold 536974. We get “536479” which is the next greater number for input 534976.
declare variable empty_string=0;
Read each char from file and check whether it is " " .
if(read_charector()==" ") empty_string++;
after reading all the data o/p "empty_string + 1 ".
pavelkalinnikov yaa you are right . we do not need to sort we just need to reverse that range.. tanq bro for info :)
- kavetiraviteja1992 January 12, 2015