Find a string such that every character is lexicographically greater than its immediate next character | C ++ program to print a string in reverse alphabetical order upto given number ; Function that prints the required string ; Find modulus with 26 ; Print extra characters required ; Print the given reverse string countOfStr times ; Driver Code ; Initialize a string in reverse order
#include <bits/stdc++.h> NEW_LINE using namespace std ; string printString ( int n , string str ) { string str2 = " " ; int extraChar = n % 26 ; if ( extraChar >= 1 ) { for ( int i = 26 - ( extraChar + 1 ) ; i <= 25 ; i ++ ) str2 += str [ i ] ; } int countOfStr = n / 26 ; for ( int i = 1 ; i <= countOfStr ; i ++ ) { for ( int j = 0 ; j < 26 ; j ++ ) str2 += str [ j ] ; } return str2 ; } int main ( ) { int n = 30 ; string str = " zyxwvutsrqponmlkjihgfedcba " ; cout << printString ( n , str ) ; return 0 ; }