codeparrot/xlcost-text-to-code huggingface dataset:
Check if any permutation of a large number is divisible by 8 | C ++ program to check if any permutation of a large number is divisible by 8 or not ; Function to check if any permutation of a large number is divisible by 8 ; Less than three digit number can be checked directly . ; check for the reverse of a number ; Stores the Frequency of characters in the n . ; Iterates for all three digit numbers divisible by 8 ; stores the frequency of all single digit in three - digit number ; check if the original number has the digit ; when all are checked its not possible ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool solve ( string n , int l ) { if ( l < 3 ) { if ( stoi ( n ) % 8 == 0 ) return true ; reverse ( n . begin ( ) , n . end ( ) ) ; if ( stoi ( n ) % 8 == 0 ) return true ; return false ; } int hash [ 10 ] = { 0 } ; for ( int i = 0 ; i < l ; i ++ ) hash [ n [ i ] - '0' ] ++ ; for ( int i = 104 ; i < 1000 ; i += 8 ) { int dup = i ; int freq [ 10 ] = { 0 } ; freq [ dup % 10 ] ++ ; dup = dup / 10 ; freq [ dup % 10 ] ++ ; dup = dup / 10 ; freq [ dup % 10 ] ++ ; dup = i ; if ( freq [ dup % 10 ] > hash [ dup % 10 ] ) continue ; dup = dup / 10 ; if ( freq [ dup % 10 ] > hash [ dup % 10 ] ) continue ; dup = dup / 10 ; if ( freq [ dup % 10 ] > hash [ dup % 10 ] ) continue ; return true ; } return false ; } int main ( ) { string number = "31462708" ; int l = number . length ( ) ; if ( solve ( number , l ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }
Lexicographically smallest string formed by appending a character from the first K characters of a given string | C ++ program to find the new string after performing deletions and append operation in the string s ; Function to find the new string thus formed by removing characters ; new string ; Remove characters until the string is empty ; Traverse to find the smallest character in the first k characters ; append the smallest character ; removing the lexicographically smallest character from the string ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; string newString ( string s , int k ) { string X = " " ; while ( s . length ( ) > 0 ) { char temp = s [ 0 ] ; for ( long long i = 1 ; i < k and i < s . length ( ) ; i ++ ) { if ( s [ i ] < temp ) { temp = s [ i ] ; } } X = X + temp ; for ( long long i = 0 ; i < k ; i ++ ) { if ( s [ i ] == temp ) { s . erase ( s . begin ( ) + i ) ; break ; } } } return X ; } int main ( ) { string s = " gaurang " ; int k = 3 ; cout << newString ( s , k ) ; }
Palindrome by swapping only one character | C ++ program palindrome by swapping only one character ; counts the number of differences which prevents the string from being palindrome . ; keeps a record of the characters that prevents the string from being palindrome . ; loops from the start of a string till the midpoint of the string ; difference is encountered preventing the string from being palindrome ; 3 rd differences encountered and its no longer possible to make is palindrome by one swap ; record the different character ; store the different characters ; its already palindrome ; only one difference is found ; if the middleChar matches either of the difference producing characters , return true ; two differences are found ; if the characters contained in the two sets are same , return true ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isPalindromePossible ( string input ) { int len = input . length ( ) ; int diffCount = 0 , i ; char diff [ 2 ] [ 2 ] ; for ( i = 0 ; i < len / 2 ; i ++ ) { if ( input [ i ] != input [ len - i - 1 ] ) { if ( diffCount == 2 ) return false ; diff [ diffCount ] [ 0 ] = input [ i ] ; diff [ diffCount ++ ] [ 1 ] = input [ len - i - 1 ] ; } } switch ( diffCount ) { case 0 : return true ; case 1 : { char midChar = input [ i ] ; if ( len % 2 != 0 and ( diff [ 0 ] [ 0 ] == midChar or diff [ 0 ] [ 1 ] == midChar ) ) return true ; } case 2 : if ( ( diff [ 0 ] [ 0 ] == diff [ 1 ] [ 0 ] and diff [ 0 ] [ 1 ] == diff [ 1 ] [ 1 ] ) or ( diff [ 0 ] [ 0 ] == diff [ 1 ] [ 1 ] and diff [ 0 ] [ 1 ] == diff [ 1 ] [ 0 ] ) ) return true ; } return false ; } int main ( ) { cout << boolalpha << isPalindromePossible ( " bbg " ) << endl ; cout << boolalpha << isPalindromePossible ( " bdababd " ) << endl ; cout << boolalpha << isPalindromePossible ( " gcagac " ) << endl ; return 0 ; }
Convert String into Binary Sequence | C ++ program to convert string into binary string ; utility function ; convert each char to ASCII value ; Convert ASCII value to binary ; driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void strToBinary ( string s ) { int n = s . length ( ) ; for ( int i = 0 ; i <= n ; i ++ ) { int val = int ( s [ i ] ) ; string bin = " " ; while ( val > 0 ) { ( val % 2 ) ? bin . push_back ( '1' ) : bin . push_back ( '0' ) ; val /= 2 ; } reverse ( bin . begin ( ) , bin . end ( ) ) ; cout << bin << " ▁ " ; } } int main ( ) { string s = " geeks " ; strToBinary ( s ) ; return 0 ; }
Sparse Search | C ++ program to implement binary search in a sparse array . ; Binary Search in an array with blanks ; Modified Part ; Search for both side for a non empty string ; No non - empty string on both sides ; Normal Binary Search ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int binarySearch ( string * arr , int low , int high , string x ) { if ( low > high ) return -1 ; int mid = ( low + high ) / 2 ; if ( arr [ mid ] == " " ) { int left = mid - 1 ; int right = mid + 1 ; while ( 1 ) { if ( left < low && right > high ) return -1 ; if ( left >= low && arr [ left ] != " " ) { mid = left ; break ; } else if ( right <= high && arr [ right ] != " " ) { mid = right ; break ; } left -- ; right ++ ; } } if ( arr [ mid ] == x ) return mid ; else if ( arr [ mid ] > x ) return binarySearch ( arr , low , mid - 1 , x ) ; else return binarySearch ( arr , mid + 1 , high , x ) ; } int sparseSearch ( string arr [ ] , string x , int n ) { return binarySearch ( arr , 0 , n - 1 , x ) ; } int main ( ) { ios_base :: sync_with_stdio ( false ) ; string arr [ ] = { " for " , " geeks " , " " , " " , " " , " " , " ide " , " practice " , " " , " " , " " , " quiz " } ; string x = " geeks " ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int index = sparseSearch ( arr , x , n ) ; if ( index != -1 ) cout << x << " ▁ found ▁ at ▁ index ▁ " << index << " STRNEWLINE " ; else cout << x << " ▁ not ▁ found STRNEWLINE " ; return 0 ; }
Print distinct sorted permutations with duplicates allowed in input | C ++ program to print all permutations of a string in sorted order . ; Calculating factorial of a number ; Method to find total number of permutations ; Building Map to store frequencies of all characters . ; Traversing map and finding duplicate elements . ; Start traversing from the end and find position ' i - 1' of the first character which is greater than its successor . ; Finding smallest character after ' i - 1' and greater than temp [ i - 1 ] ; Swapping the above found characters . ; Sort all digits from position next to ' i - 1' to end of the string . ; Print the String ; Sorting String ; Print first permutation ; Finding the total permutations ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int factorial ( int n ) { int f = 1 ; for ( int i = 1 ; i <= n ; i ++ ) f = f * i ; return f ; } int calculateTotal ( string temp , int n ) { int f = factorial ( n ) ; map < char , int > hm ; for ( int i = 0 ; i < temp . length ( ) ; i ++ ) { hm [ temp [ i ] ] ++ ; } for ( auto e : hm ) { int x = e . second ; if ( x > 1 ) { int temp5 = factorial ( x ) ; f /= temp5 ; } return f ; } } static void nextPermutation ( string & temp ) { int i ; for ( i = temp . length ( ) - 1 ; i > 0 ; i -- ) if ( temp [ i ] > temp [ i - 1 ] ) break ; int min = i ; int j , x = temp [ i - 1 ] ; for ( j = i + 1 ; j < temp . length ( ) ; j ++ ) if ( ( temp [ j ] < temp [ min ] ) and ( temp [ j ] > x ) ) min = j ; swap ( temp [ i - 1 ] , temp [ min ] ) ; sort ( temp . begin ( ) + i , temp . end ( ) ) ; cout << temp << endl ; } void printAllPermutations ( string s ) { string temp ( s ) ; sort ( temp . begin ( ) , temp . end ( ) ) ; cout << temp << endl ; int total = calculateTotal ( temp , temp . length ( ) ) ; for ( int i = 1 ; i < total ; i ++ ) { nextPermutation ( temp ) ; } } int main ( ) { string s = " AAB " ; printAllPermutations ( s ) ; }
Swap Nodes in Binary tree of every k 'th level | c ++ program swap nodes ; A Binary Tree Node ; function to create a new tree node ; swap two Node ; A utility function swap left - node & right node of tree of every k 'th level ; base case ; if current level + 1 is present in swap vector then we swap left & right node ; Recur for left and right subtrees ; This function mainly calls recursive function swapEveryKLevelUtil ( ) ; call swapEveryKLevelUtil function with initial level as 1. ; Utility method for inorder tree traversal ; Driver Code ; 1 / \ 2 3 / / \ 4 7 8
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; Node * newNode ( int data ) { Node * temp = new Node ; temp -> data = data ; temp -> left = temp -> right = NULL ; return temp ; } void Swap ( Node * * a , Node * * b ) { Node * temp = * a ; * a = * b ; * b = temp ; } void swapEveryKLevelUtil ( Node * root , int level , int k ) { if ( root == NULL || ( root -> left == NULL && root -> right == NULL ) ) return ; if ( ( level + 1 ) % k == 0 ) Swap ( & root -> left , & root -> right ) ; swapEveryKLevelUtil ( root -> left , level + 1 , k ) ; swapEveryKLevelUtil ( root -> right , level + 1 , k ) ; } void swapEveryKLevel ( Node * root , int k ) { swapEveryKLevelUtil ( root , 1 , k ) ; } void inorder ( Node * root ) { if ( root == NULL ) return ; inorder ( root -> left ) ; cout << root -> data << " ▁ " ; inorder ( root -> right ) ; } int main ( ) { struct Node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 3 ) ; root -> left -> left = newNode ( 4 ) ; root -> right -> right = newNode ( 8 ) ; root -> right -> left = newNode ( 7 ) ; int k = 2 ; cout << " Before ▁ swap ▁ node ▁ : " << endl ; inorder ( root ) ; swapEveryKLevel ( root , k ) ; cout << " After swap Node : " << endl ; inorder ( root ) ; return 0 ; }
Convert a sentence into its equivalent mobile numeric keypad sequence | C ++ implementation to convert a sentence into its equivalent mobile numeric keypad sequence ; Function which computes the sequence ; length of input string ; Checking for space ; Calculating index for each character ; Output sequence ; Driver function ; storing the sequence in array
#include <bits/stdc++.h> NEW_LINE using namespace std ; string printSequence ( string arr [ ] , string input ) { string output = " " ; int n = input . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( input [ i ] == ' ▁ ' ) output = output + "0" ; else { int position = input [ i ] - ' A ' ; output = output + arr [ position ] ; } } return output ; } int main ( ) { string str [ ] = { "2" , "22" , "222" , "3" , "33" , "333" , "4" , "44" , "444" , "5" , "55" , "555" , "6" , "66" , "666" , "7" , "77" , "777" , "7777" , "8" , "88" , "888" , "9" , "99" , "999" , "9999" } ; string input = " GEEKSFORGEEKS " ; cout << printSequence ( str , input ) ; return 0 ; }
Longest Uncommon Subsequence | CPP program to find longest uncommon subsequence using naive method ; function to calculate length of longest uncommon subsequence ; creating an unordered map to map strings to their frequency ; traversing all elements of vector strArr ; Creating all possible subsequences , i . e 2 ^ n ; ( ( i >> j ) & 1 ) determines which character goes into string t ; If common subsequence is found , increment its frequency ; traversing the map ; if frequency equals 1 ; Driver code ; Input strings
#include <iostream> NEW_LINE #include <unordered_map> NEW_LINE #include <vector> NEW_LINE using namespace std ; int findLUSlength ( string a , string b ) { unordered_map < string , int > map ; vector < string > strArr ; strArr . push_back ( a ) ; strArr . push_back ( b ) ; for ( string s : strArr ) { for ( int i = 0 ; i < ( 1 << s . length ( ) ) ; i ++ ) { string t = " " ; for ( int j = 0 ; j < s . length ( ) ; j ++ ) { if ( ( ( i >> j ) & 1 ) != 0 ) t += s [ j ] ; } if ( map . count ( t ) ) map [ t ] ++ ; else map [ t ] = 1 ; } } int res = 0 ; for ( auto a : map ) { if ( a . second == 1 ) res = max ( res , ( int ) a . first . length ( ) ) ; } return res ; } int main ( ) { string a = " abcdabcd " , b = " abcabc " ; cout << findLUSlength ( a , b ) ; return 0 ; }
Round the given number to nearest multiple of 10 | C ++ code for above approach ; Program to round the number to the nearest number having one 's digit 0 ; last character is 0 then return the original string ; if last character is 1 or 2 or 3 or 4 or 5 make it 0 ; process carry ; return final string ; Driver code ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; string Round ( string s , int n ) { string c = s ; if ( c [ n - 1 ] == '0' ) return s ; else if ( c [ n - 1 ] == '1' c [ n - 1 ] == '2' c [ n - 1 ] == '3' c [ n - 1 ] == '4' c [ n - 1 ] == '5' ) { c [ n - 1 ] = '0' ; return c ; } else { c [ n - 1 ] = '0' ; for ( int i = n - 2 ; i >= 0 ; i -- ) { if ( c [ i ] == '9' ) c [ i ] = '0' ; else { int t = c [ i ] - '0' + 1 ; c [ i ] = ( char ) ( 48 + t ) ; break ; } } } string s1 = c ; if ( s1 [ 0 ] == '0' ) s1 = "1" + s1 ; return s1 ; } int main ( ) { string s = "5748965412485599999874589965999" ; int n = s . length ( ) ; cout << Round ( s , n ) << endl ; return 0 ; }
Check whether given floating point number is even or odd | CPP program to check whether given floating point number is even or odd ; Function to check even or odd . ; Loop to traverse number from LSB ; We ignore trailing 0 s after dot ; If it is ' . ' we will check next digit and it means decimal part is traversed . ; If digit is divisible by 2 means even number . ; Driver Function
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isEven ( string s ) { int l = s . length ( ) ; bool dotSeen = false ; for ( int i = l - 1 ; i >= 0 ; i -- ) { if ( s [ i ] == '0' && dotSeen == false ) continue ; if ( s [ i ] == ' . ' ) { dotSeen = true ; continue ; } if ( ( s [ i ] - '0' ) % 2 == 0 ) return true ; return false ; } } int main ( ) { string s = "100.70" ; if ( isEven ( s ) ) cout << " Even " ; else cout << " Odd " ; return 0 ; }
Minimum cost to construct a string | C ++ Program to find minimum cost to construct a string ; Initially all characters are un - seen ; Marking seen characters ; Count total seen character , and that is the cost ; Driver Code ; s is the string that needs to be constructed
#include <iostream> NEW_LINE using namespace std ; int minCost ( string & s ) { bool alphabets [ 26 ] = { false } ; for ( int i = 0 ; i < s . size ( ) ; i ++ ) alphabets [ s [ i ] - 97 ] = true ; int count = 0 ; for ( int i = 0 ; i < 26 ; i ++ ) if ( alphabets [ i ] ) count ++ ; return count ; } int main ( ) { string s = " geeksforgeeks " ; cout << " Total ▁ cost ▁ to ▁ construct ▁ " << s << " ▁ is ▁ " << minCost ; return 0 ; }
Root to leaf paths having equal lengths in a Binary Tree | C ++ program to count root to leaf paths of different lengths . ; A binary tree node ; utility that allocates a new node with the given data and NULL left and right pointers . ; Function to store counts of different root to leaf path lengths in hash map m . ; Base condition ; If leaf node reached , increment count of path length of this root to leaf path . ; Recursively call for left and right subtrees with path lengths more than 1. ; A wrapper over pathCountUtil ( ) ; create an empty hash table ; Recursively check in left and right subtrees . ; Print all path lenghts and their counts . ; Driver program to run the case
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; struct Node * newnode ( int data ) { struct Node * node = new Node ; node -> data = data ; node -> left = node -> right = NULL ; return ( node ) ; } void pathCountUtil ( Node * node , unordered_map < int , int > & m , int path_len ) { if ( node == NULL ) return ; if ( node -> left == NULL && node -> right == NULL ) { m [ path_len ] ++ ; return ; } pathCountUtil ( node -> left , m , path_len + 1 ) ; pathCountUtil ( node -> right , m , path_len + 1 ) ; } void pathCounts ( Node * root ) { unordered_map < int , int > m ; pathCountUtil ( root , m , 1 ) ; for ( auto itr = m . begin ( ) ; itr != m . end ( ) ; itr ++ ) cout << itr -> second << " ▁ paths ▁ have ▁ length ▁ " << itr -> first << endl ; } int main ( ) { struct Node * root = newnode ( 8 ) ; root -> left = newnode ( 5 ) ; root -> right = newnode ( 4 ) ; root -> left -> left = newnode ( 9 ) ; root -> left -> right = newnode ( 7 ) ; root -> right -> right = newnode ( 11 ) ; root -> right -> right -> left = newnode ( 3 ) ; pathCounts ( root ) ; return 0 ; }
Simplify the directory path ( Unix like ) | C ++ implementation of optimized Approach 1 ; function to simplify a Unix - styled absolute path ; using vector in place of stack ; forming the current directory . ; if " . . " , we pop . ; do nothing ( added for better understanding . ) ; push the current directory into the vector . ; forming the ans ; vector is empty ; Driver Code ; absolute path which we have to simplify .
#include <bits/stdc++.h> NEW_LINE using namespace std ; string simplify ( string path ) { vector < string > v ; int n = path . length ( ) ; string ans ; for ( int i = 0 ; i < n ; i ++ ) { string dir = " " ; while ( i < n && path [ i ] != ' / ' ) { dir += path [ i ] ; i ++ ; } if ( dir == " . . " ) { if ( ! v . empty ( ) ) v . pop_back ( ) ; } else if ( dir == " . " dir == " " ) { } else { v . push_back ( dir ) ; } } for ( auto i : v ) { ans += " / " + i ; } if ( ans == " " ) return " / " ; return ans ; } int main ( ) { string str ( " / a / . / b / . . / . . / c / " ) ; string res = simplify ( str ) ; cout << res ; return 0 ; }
Length of the smallest sub | C ++ program to find the length of the smallest substring consisting of maximum distinct characters ; Find maximum distinct characters in any string ; Initialize all character 's count with 0 ; Increase the count in array if a character is found ; size of given string ; Find maximum distinct characters in any string ; result ; Brute force approach to find all substrings ; We have to check here both conditions together 1. substring ' s ▁ distinct ▁ characters ▁ is ▁ equal ▁ ▁ to ▁ maximum ▁ distinct ▁ characters ▁ ▁ 2 . ▁ substring ' s length should be minimum ; Driver program to test above function ; Input String
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define NO_OF_CHARS  256 NEW_LINE int max_distinct_char ( string str , int n ) { int count [ NO_OF_CHARS ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) count [ str [ i ] ] ++ ; int max_distinct = 0 ; for ( int i = 0 ; i < NO_OF_CHARS ; i ++ ) if ( count [ i ] != 0 ) max_distinct ++ ; return max_distinct ; } int smallesteSubstr_maxDistictChar ( string str ) { int n = str . size ( ) ; int max_distinct = max_distinct_char ( str , n ) ; int minl = n ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { string subs = str . substr ( i , j ) ; int subs_lenght = subs . size ( ) ; int sub_distinct_char = max_distinct_char ( subs , subs_lenght ) ; if ( subs_lenght < minl && max_distinct == sub_distinct_char ) { minl = subs_lenght ; } } } return minl ; } int main ( ) { string str = " AABBBCBB " ; int len = smallesteSubstr_maxDistictChar ( str ) ; cout << " ▁ The ▁ length ▁ of ▁ the ▁ smallest ▁ substring " " ▁ consisting ▁ of ▁ maximum ▁ distinct ▁ " " characters ▁ : ▁ " << len ; return 0 ; }
Evaluate a boolean expression represented as string | C ++ program to evaluate value of an expression . ; Evaluates boolean expression and returns the result ; Traverse all operands by jumping a character after every iteration . ; If operator next to current operand is AND . ; If operator next to current operand is OR . ; If operator next to current operand is XOR ( Assuming a valid input ) ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int evaluateBoolExpr ( string s ) { int n = s . length ( ) ; for ( int i = 0 ; i < n ; i += 2 ) { if ( s [ i + 1 ] == ' A ' ) { if ( s [ i + 2 ] == '0' s [ i ] == '0' ) s [ i + 2 ] = '0' ; else s [ i + 2 ] = '1' ; } else if ( s [ i + 1 ] == ' B ' ) { if ( s [ i + 2 ] == '1' s [ i ] == '1' ) s [ i + 2 ] = '1' ; else s [ i + 2 ] = '0' ; } else { if ( s [ i + 2 ] == s [ i ] ) s [ i + 2 ] = '0' ; else s [ i + 2 ] = '1' ; } } return s [ n - 1 ] - '0' ; } int main ( ) { string s = "1C1B1B0A0" ; cout << evaluateBoolExpr ( s ) ; return 0 ; }
Efficiently find first repeated character in a string without using any additional data structure in one traversal | Efficiently check First repeated character in C ++ program ; Returns - 1 if all characters of str are unique . Assumptions : ( 1 ) str contains only characters from ' a ' to ' z ' ( 2 ) integers are stored using 32 bits ; An integer to store presence / absence of 26 characters using its 32 bits . ; If bit corresponding to current character is already set ; set bit in checker ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int FirstRepeated ( string str ) { int checker = 0 ; for ( int i = 0 ; i < str . length ( ) ; ++ i ) { int val = ( str [ i ] - ' a ' ) ; if ( ( checker & ( 1 << val ) ) > 0 ) return i ; checker |= ( 1 << val ) ; } return -1 ; } int main ( ) { string s = " abcfdeacf " ; int i = FirstRepeated ( s ) ; if ( i != -1 ) cout << " Char ▁ = ▁ " << s [ i ] << " ▁ and ▁ Index ▁ = ▁ " << i ; else cout << " No ▁ repeated ▁ Char " ; return 0 ; }
Check if a string is Pangrammatic Lipogram | C ++ program to check if a string is Pangrammatic Lipogram ; collection of letters ; function to check for a Pangrammatic Lipogram ; convert string to lowercase ; variable to keep count of all the letters not found in the string ; traverses the string for every letter of the alphabet ; if character not found in string then increment count ; Driver program to test above function
#include <bits/stdc++.h> NEW_LINE using namespace std ; string alphabets = " abcdefghijklmnopqrstuvwxyz " ; void panLipogramChecker ( string s ) { for ( int i = 0 ; i < s . length ( ) ; i ++ ) { s [ i ] = tolower ( s [ i ] ) ; } int counter = 0 ; for ( int i = 0 ; i < 26 ; i ++ ) { int pos = s . find ( alphabets [ i ] ) ; if ( pos < 0 || pos > s . length ( ) ) counter += 1 ; } if ( counter == 0 ) cout << " Pangram " << endl ; else if ( counter >= 2 ) cout << " Not ▁ a ▁ pangram ▁ but ▁ might ▁ a ▁ lipogram " << endl ; else cout << " Pangrammatic ▁ Lipogram " << endl ; } int main ( ) { string str = " The ▁ quick ▁ brown ▁ fox ▁ jumped ▁ over ▁ the ▁ lazy ▁ dog " ; panLipogramChecker ( str ) ; str = " The ▁ quick ▁ brown ▁ fox ▁ jumps ▁ over ▁ the ▁ lazy ▁ dog " ; panLipogramChecker ( str ) ; str = " The ▁ quick ▁ brown ▁ fox ▁ jum ▁ over ▁ the ▁ lazy ▁ dog " ; panLipogramChecker ( str ) ; }
Lexicographically n | C ++ program to print nth permutation with using next_permute ( ) ; Function to print nth permutation using next_permute ( ) ; Sort the string in lexicographically ascending order ; Keep iterating until we reach nth position ; check for nth iteration ; print string after nth iteration ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void nPermute ( string str , long int n ) { sort ( str . begin ( ) , str . end ( ) ) ; long int i = 1 ; do { if ( i == n ) break ; i ++ ; } while ( next_permutation ( str . begin ( ) , str . end ( ) ) ) ; cout << str ; } int main ( ) { string str = " GEEKSFORGEEKS " ; long int n = 100 ; nPermute ( str , n ) ; return 0 ; }