codeparrot/xlcost-text-to-code huggingface dataset:
Character whose frequency is equal to the sum of frequencies of other characters of the given string | C # implementation of the above approach . ; Function that returns true if some character exists in the given string whose frequency is equal to the sum frequencies of other characters of the string ; If string is of odd length ; To store the frequency of each character of the string ; Update the frequencies of the characters ; No such character exists ; Driver code
using System ; class GFG { static bool isFrequencyEqual ( String str , int len ) { if ( len % 2 == 1 ) { return false ; } int i ; int [ ] freq = new int [ 26 ] ; for ( i = 0 ; i < len ; i ++ ) { freq [ str [ i ] - ' a ' ] ++ ; } for ( i = 0 ; i < 26 ; i ++ ) { if ( freq [ i ] == len / 2 ) { return true ; } } return false ; } public static void Main ( ) { String str = " geeksforgeeks " ; int len = str . Length ; if ( isFrequencyEqual ( str , len ) ) { Console . WriteLine ( " Yes " ) ; } else { Console . WriteLine ( " No " ) ; } } }
Minimum replacements to make adjacent characters unequal in a ternary string | C # program to count the minimal replacements such that adjacent characters are unequal ; Function to count the number of minimal replacements ; Find the length of the String ; Iterate in the String ; Check if adjacent is similar ; If not the last pair ; Check for character which is not same in i + 1 and i - 1 ; else Last pair ; Check for character which is not same in i - 1 index ; Driver Code
using System ; class GFG { static readonly int MAX = 26 ; static int countMinimalReplacements ( char [ ] s ) { int n = s . Length ; int cnt = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( s [ i ] == s [ i - 1 ] ) { cnt += 1 ; if ( i != ( n - 1 ) ) { foreach ( char it in "012" . ToCharArray ( ) ) { if ( it != s [ i + 1 ] && it != s [ i - 1 ] ) { s [ i ] = it ; break ; } } } { foreach ( char it in "012" . ToCharArray ( ) ) { if ( it != s [ i - 1 ] ) { s [ i ] = it ; break ; } } } } } return cnt ; } public static void Main ( String [ ] args ) { String s = "201220211" ; Console . WriteLine ( countMinimalReplacements ( s . ToCharArray ( ) ) ) ; } }
Sub | C # implementation of the approach ; Function that returns the index of next occurrence of the character c in string str starting from index start ; Starting from start ; If current character = c ; Not found ; Function to return the count of required sub - strings ; Stores running count of ' x ' starting from the end ; Next index of ' x ' starting from index 0 ; Next index of ' y ' starting from index 0 ; To store the count of required sub - strings ; If ' y ' appears before ' x ' it won 't contribute to a valid sub-string ; Find next occurrence of ' y ' ; If ' y ' appears after ' x ' every sub - string ending at an ' x ' appearing after this ' y ' and starting with the current ' x ' is a valid sub - string ; Find next occurrence of ' x ' ; Return the count ; Driver code
using System ; public class GFG { static int nextIndex ( string str , int start , char c ) { for ( int i = start ; i < str . Length ; i ++ ) { if ( str [ i ] == c ) return i ; } return - 1 ; } static int countSubStrings ( string str ) { int i , n = str . Length ; int [ ] countX = new int [ n ] ; int count = 0 ; for ( i = n - 1 ; i >= 0 ; i -- ) { if ( str [ i ] == ' x ' ) count ++ ; countX [ i ] = count ; } int nextIndexX = nextIndex ( str , 0 , ' x ' ) ; int nextIndexY = nextIndex ( str , 0 , ' y ' ) ; count = 0 ; while ( nextIndexX != - 1 && nextIndexY != - 1 ) { if ( nextIndexX > nextIndexY ) { nextIndexY = nextIndex ( str , nextIndexY + 1 , ' y ' ) ; continue ; } else { count += countX [ nextIndexY ] ; nextIndexX = nextIndex ( str , nextIndexX + 1 , ' x ' ) ; } } return count ; } public static void Main ( ) { string s = " xyyxx " ; Console . WriteLine ( countSubStrings ( s ) ) ; } }
Check whether the frequencies of all the characters in a string are prime or not | C # implementation of above approach ; function that returns true if n is prime else false ; 1 is not prime ; check if there is any factor or not ; function that returns true if the frequencies of all the characters of s are prime ; create a map to store the frequencies of characters ; for ( int i = 0 ; i < s . Length ; i ++ ) update the frequency ; check whether all the frequencies are prime or not ; Driver code ; if all the frequencies are prime
using System ; using System . Collections . Generic ; class GFG { static bool isPrime ( int n ) { int i ; if ( n == 1 ) { return false ; } for ( i = 2 ; i <= Math . Sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { return false ; } } return true ; } static bool check_frequency ( char [ ] s ) { Dictionary < char , int > m = new Dictionary < char , int > ( ) ; { if ( m . ContainsKey ( s [ i ] ) ) { var c = m [ s [ i ] ] + 1 ; m . Remove ( s [ i ] ) ; m . Add ( s [ i ] , c ) ; } else { m . Add ( s [ i ] , 1 ) ; } } for ( char ch = ' a ' ; ch <= ' z ' ; ch ++ ) { if ( m . ContainsKey ( ch ) && m [ ch ] > 0 && ! isPrime ( m [ ch ] ) ) { return false ; } } return true ; } public static void Main ( String [ ] args ) { String s = " geeksforgeeks " ; if ( check_frequency ( s . ToCharArray ( ) ) ) { Console . WriteLine ( " Yes " ) ; } else { Console . WriteLine ( " No " ) ; } } }
Find the count of substrings in alphabetic order | C # to find the number of substrings in alphabetical order ; Function to find number of substrings ; Iterate over string length ; if any two chars are in alphabetic order ; find next char not in order ; return the result ; Driver function
using System ; public class Solution { public static int findSubstringCount ( string str ) { int result = 0 ; int n = str . Length ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( ( char ) ( str [ i ] + 1 ) == str [ i + 1 ] ) { result ++ ; while ( ( char ) ( str [ i ] + 1 ) == str [ i + 1 ] ) { i ++ ; } } } return result ; } public static void Main ( string [ ] args ) { string str = " alphabet " ; Console . WriteLine ( findSubstringCount ( str ) ) ; } }
Reduce the string by removing K consecutive identical characters | C # implementation of the above approach ; Function to find the reduced string ; Base Case ; Creating a stack of type Pair ; Length of the string S ; iterate through the string ; if stack is empty then simply add the character with count 1 else check if character is same as top of stack ; if character at top of stack is same as current character increase the number of repetitions in the top of stack by 1 ; if character at top of stack is not same as current character push the character along with count 1 into the top of stack ; iterate through the stack Use string ( int , char ) in order to replicate the character multiple times and convert into string then add in front of output string ; Driver code
using System ; using System . Collections . Generic ; public class GFG { public static String reduced_String ( int k , String s ) { if ( k == 1 ) { return " " ; } Stack < Pair > st = new Stack < Pair > ( ) ; int l = s . Length ; for ( int i = 0 ; i < l ; i ++ ) { if ( st . Count == 0 ) { st . Push ( new Pair ( s [ i ] , 1 ) ) ; continue ; } if ( st . Peek ( ) . c == s [ i ] ) { Pair p = st . Peek ( ) ; st . Pop ( ) ; p . ctr += 1 ; if ( p . ctr == k ) { continue ; } else { st . Push ( p ) ; } } else { st . Push ( new Pair ( s [ i ] , 1 ) ) ; } } String ans = " " ; while ( st . Count > 0 ) { char c = st . Peek ( ) . c ; int cnt = st . Peek ( ) . ctr ; while ( cnt -- > 0 ) ans = c + ans ; st . Pop ( ) ; } return ans ; } public static void Main ( String [ ] args ) { int k = 2 ; String st = " geeksforgeeks " ; String ans = reduced_String ( k , st ) ; Console . Write ( ans ) ; } public class Pair { public char c ; public int ctr ; public Pair ( char c , int ctr ) { this . c = c ; this . ctr = ctr ; } } }
First non | C # program to find first non - repeating character using 1D array and one traversal . ; The function returns index of the first non - repeating character in a string . If all characters are repeating then returns INT_MAX ; Initialize all characters as absent . ; After below loop , the value of arr [ x ] is going to be index of x if x appears only once . Else the value is going to be either - 1 or - 2. ; If this character occurs only once and appears before the current result , then update the result ; Driver Code
using System ; class GFG { static int firstNonRepeating ( String str ) { int NO_OF_CHARS = 256 ; int [ ] arr = new int [ NO_OF_CHARS ] ; for ( int i = 0 ; i < NO_OF_CHARS ; i ++ ) arr [ i ] = - 1 ; for ( int i = 0 ; i < str . Length ; i ++ ) { if ( arr [ str [ i ] ] == - 1 ) arr [ str [ i ] ] = i ; else arr [ str [ i ] ] = - 2 ; } int res = int . MaxValue ; for ( int i = 0 ; i < NO_OF_CHARS ; i ++ ) if ( arr [ i ] >= 0 ) res = Math . Min ( res , arr [ i ] ) ; return res ; } public static void Main ( ) { String str = " geeksforgeeks " ; int index = firstNonRepeating ( str ) ; if ( index == int . MaxValue ) Console . Write ( " Either ▁ all ▁ characters ▁ are ▁ " + " repeating ▁ or ▁ string ▁ is ▁ empty " ) ; else Console . Write ( " First ▁ non - repeating ▁ character " + " ▁ is ▁ " + str [ index ] ) ; } }
Character replacement after removing duplicates from a string | C # program for character replacement after String minimization ; Function to minimize String ; duplicate characters are removed ; checks if character has previously occurred or not if not then add it to the minimized String ' mstr ' ; return mstr ; minimized String ; Utility function to print the minimized , replaced String ; Creating final String by replacing character ; index calculation ; final String ; Driver Code
using System ; class GFG { static String minimize ( string str ) { string mstr = " ▁ " ; int l , i ; int [ ] flagchar = new int [ 26 ] ; char ch ; l = str . Length ; for ( i = 0 ; i < str . Length ; i ++ ) { ch = str [ i ] ; if ( flagchar [ ch - 97 ] == 0 ) { mstr = mstr + ch ; flagchar [ ch - 97 ] = 1 ; } } } static void replaceMinimizeUtil ( string str ) { string minimizedStr , finalStr = " " ; int i , index , l ; char ch ; l = str . Length ; for ( i = 0 ; i < minimizedStr . Length ; i ++ ) { ch = minimizedStr [ i ] ; index = ( ch * ch ) % l ; finalStr = finalStr + str [ index ] ; } Console . Write ( " Final ▁ String : ▁ " + finalStr ) ; } public static void Main ( ) { string str = " geeks " ; replaceMinimizeUtil ( str ) ; } }
Latin alphabet cipher | C # program to demonstrate Latin Alphabet Cipher ; function for calculating the encryption ; Driver Code
using System ; public class LatinCipher { static void cipher ( String str ) { for ( int i = 0 ; i < str . Length ; i ++ ) { if ( ! char . IsLetter ( str [ i ] ) && str [ i ] != ' ▁ ' ) { Console . WriteLine ( " Enter ▁ only ▁ alphabets ▁ and ▁ space " ) ; return ; } } Console . WriteLine ( " Encrypted ▁ Code ▁ using ▁ Latin ▁ Alphabet " ) ; for ( int i = 0 ; i < str . Length ; i ++ ) { if ( str [ i ] >= ' A ' && str [ i ] <= ' Z ' ) { Console . Write ( str [ i ] - ' A ' + 1 + " ▁ " ) ; } else if ( str [ i ] >= ' a ' && str [ i ] <= ' z ' ) { Console . Write ( str [ i ] - ' a ' + 1 + " ▁ " ) ; } if ( str [ i ] == ' ▁ ' ) Console . Write ( str [ i ] ) ; } Console . WriteLine ( ) ; } public static void Main ( String [ ] args ) { String str = " geeksforgeeks " ; cipher ( str ) ; } }
Count palindrome words in a sentence | C # program to count number of palindrome words in a sentence ; Function to check if a word is palindrome ; Function to count palindrome words ; to check last word for palindrome ; to store each word ; extracting each word ; Driver code
using System ; class GFG { public static bool checkPalin ( string word ) { int n = word . Length ; word = word . ToLower ( ) ; for ( int i = 0 ; i < n ; i ++ , n -- ) { if ( word [ i ] != word [ n - 1 ] ) { return false ; } } return true ; } public static int countPalin ( string str ) { str = str + " ▁ " ; string word = " " ; int count = 0 ; for ( int i = 0 ; i < str . Length ; i ++ ) { char ch = str [ i ] ; if ( ch != ' ▁ ' ) { word = word + ch ; } else { if ( checkPalin ( word ) ) { count ++ ; } word = " " ; } } return count ; } public static void Main ( string [ ] args ) { Console . WriteLine ( countPalin ( " Madam ▁ " + " Arora ▁ teaches ▁ malayalam " ) ) ; Console . WriteLine ( countPalin ( " Nitin ▁ " + " speaks ▁ malayalam " ) ) ; } }
Remove the forbidden strings | C # program to remove forbidden strings ; number of forbidden strings ; original string ; forbidden strings ; to store original string as character array ; letter to replace and occur max number of times ; pre [ ] keeps record of the characters of w that need to be changed ; Function to check if the particular substring is present in w at position ; If length of substring from this position is greater than length of w then return ; n and n1 are used to check for substring without considering the case of the letters in w by comparing the difference of ASCII values ; If same == true then it means a substring was found starting at position therefore all characters from position to length of substring found need to be changed therefore they need to be marked ; Function performing calculations . ; To verify if any substring is starting from index i ; Modifying the string w according to th rules ; This condition checks if w [ i ] = upper ( letter ) ; This condition checks if w [ i ] is any lowercase letter apart from letter . If true replace it with letter ; This condition checks if w [ i ] is any uppercase letter apart from letter . If true then replace it with upper ( letter ) . ; Driver Code
using System ; class GFG { public static int n ; public static string z ; public static string [ ] s = new string [ 100 ] ; public static char [ ] w ; public static char letter ; public static bool [ ] pre = new bool [ 100 ] ; public static void verify ( int position , int index ) { int l = z . Length ; int k = s [ index ] . Length ; if ( position + k > l ) { return ; } bool same = true ; for ( int i = position ; i < position + k ; i ++ ) { int n , n1 ; char ch = w [ i ] ; char ch1 = s [ index ] [ i - position ] ; if ( ch >= ' a ' && ch <= ' z ' ) { n = ch - ' a ' ; } else { n = ch - ' A ' ; } if ( ch1 >= ' a ' && ch1 <= ' z ' ) { n1 = ch1 - ' a ' ; } else { n1 = ch1 - ' A ' ; } if ( n != n1 ) { same = false ; } } if ( same == true ) { for ( int i = position ; i < position + k ; i ++ ) { pre [ i ] = true ; } return ; } } public static void solve ( ) { w = z . ToCharArray ( ) ; letter = ' d ' ; int l = z . Length ; int p = letter - ' a ' ; for ( int i = 0 ; i < 100 ; i ++ ) { pre [ i ] = false ; } for ( int i = 0 ; i < l ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { verify ( i , j ) ; } } for ( int i = 0 ; i < l ; i ++ ) { if ( pre [ i ] == true ) { if ( w [ i ] == letter ) { w [ i ] = ( letter == ' a ' ) ? ' b ' : ' a ' ; } else if ( w [ i ] == ( char ) ( ( int ) ' A ' + p ) ) { w [ i ] = ( letter == ' a ' ) ? ' B ' : ' A ' ; } else if ( w [ i ] >= ' a ' && w [ i ] <= ' z ' ) { w [ i ] = letter ; } else if ( w [ i ] >= ' A ' && w [ i ] <= ' Z ' ) { w [ i ] = ( char ) ( ( int ) ' A ' + p ) ; } } } Console . WriteLine ( w ) ; } public static void Main ( string [ ] args ) { n = 3 ; s [ 0 ] = " etr " ; s [ 1 ] = " ed " ; s [ 2 ] = " ied " ; z = " PEtrUnited " ; solve ( ) ; } }
Round the given number to nearest multiple of 10 | C # Code for Round the given number to nearest multiple of 10 ; function to round the number ; Smaller multiple ; Larger multiple ; Return of closest of two ; Driver program
using System ; class GFG { static int round ( int n ) { int a = ( n / 10 ) * 10 ; int b = a + 10 ; return ( n - a > b - n ) ? b : a ; } public static void Main ( ) { int n = 4722 ; Console . WriteLine ( round ( n ) ) ; } }
Breaking a number such that first part is integral division of second by a power of 10 | C # program to count ways to divide a String in two parts a and b such that b / pow ( 10 , p ) == a ; subString representing int a ; no of digits in a ; consider only most significant l1 characters of remaining String for int b ; if any of a or b contains leading 0 s discard this combination ; if both are equal ; Driver Code
using System ; class GFG { static int calculate ( String N ) { int len = N . Length ; int l = ( len ) / 2 ; int count = 0 ; for ( int i = 1 ; i <= l ; i ++ ) { String s = N . Substring ( 0 , i ) ; int l1 = s . Length ; String t = N . Substring ( i , l1 ) ; if ( s [ 0 ] == '0' t [ 0 ] == '0' ) continue ; if ( s . CompareTo ( t ) == 0 ) count ++ ; } return count ; } public static void Main ( String [ ] args ) { String N = "2202200" ; Console . Write ( calculate ( N ) ) ; } }
Number of subsequences as " ab " in a string repeated K times | C # code to find number of subsequences of " ab " in the string S which is repeated K times . ; Count of ' a ' s ; Count of ' b ' s ; occurrence of " ab " s in string S ; Add following two : 1 ) K * ( Occurrences of " ab " in single string ) 2 ) a is from one string and b is from other . ; Driver code
using System ; class GFG { static int countOccurrences ( string s , int K ) { int n = s . Length ; int C = 0 , c1 = 0 , c2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s [ i ] == ' a ' ) c1 ++ ; if ( s [ i ] == ' b ' ) { c2 ++ ; C += c1 ; } } return C * K + ( K * ( K - 1 ) / 2 ) * c1 * c2 ; } public static void Main ( ) { string S = " abcb " ; int k = 2 ; Console . WriteLine ( countOccurrences ( S , k ) ) ; } }
String with k distinct characters and no same characters adjacent | C # program to construct a n length string with k distinct characters such that no two same characters are adjacent . ; Function to find a string of length n with k distinct characters . ; Initialize result with first k Latin letters ; Fill remaining n - k letters by repeating k letters again and again . ; Driver code
using System ; public class GFG { static string findString ( int n , int k ) { string res = " " ; for ( int i = 0 ; i < k ; i ++ ) res = res + ( char ) ( ' a ' + i ) ; int count = 0 ; for ( int i = 0 ; i < n - k ; i ++ ) { res = res + ( char ) ( ' a ' + count ) ; count ++ ; if ( count == k ) count = 0 ; } return res ; } static public void Main ( ) { int n = 5 , k = 2 ; Console . WriteLine ( findString ( n , k ) ) ; } }
Program for credit card number validation | C # program to check if a given credit card is valid or not . ; Main Method ; Return true if the card number is valid ; Get the result from Step 2 ; Return this number if it is a single digit , otherwise , return the sum of the two digits ; Return sum of odd - place digits in number ; Return true if the digit d is a prefix for number ; Return the number of digits in d ; Return the first k number of digits from number . If the number of digits in number is less than k , return number .
using System ; class CreditCard { public static void Main ( ) { long number = 5196081888500645L ; Console . Write ( number + " ▁ is ▁ " + ( isValid ( number ) ? " valid " : " invalid " ) ) ; } public static bool isValid ( long number ) { return ( getSize ( number ) >= 13 && getSize ( number ) <= 16 ) && ( prefixMatched ( number , 4 ) || prefixMatched ( number , 5 ) || prefixMatched ( number , 37 ) || prefixMatched ( number , 6 ) ) && ( ( sumOfDoubleEvenPlace ( number ) + sumOfOddPlace ( number ) ) % 10 == 0 ) ; } public static int sumOfDoubleEvenPlace ( long number ) { int sum = 0 ; String num = number + " " ; for ( int i = getSize ( number ) - 2 ; i >= 0 ; i -= 2 ) sum += getDigit ( int . Parse ( num [ i ] + " " ) * 2 ) ; return sum ; } public static int getDigit ( int number ) { if ( number < 9 ) return number ; return number / 10 + number % 10 ; } public static int sumOfOddPlace ( long number ) { int sum = 0 ; String num = number + " " ; for ( int i = getSize ( number ) - 1 ; i >= 0 ; i -= 2 ) sum += int . Parse ( num [ i ] + " " ) ; return sum ; } public static bool prefixMatched ( long number , int d ) { return getPrefix ( number , getSize ( d ) ) == d ; } public static int getSize ( long d ) { String num = d + " " ; return num . Length ; } public static long getPrefix ( long number , int k ) { if ( getSize ( number ) > k ) { String num = number + " " ; return long . Parse ( num . Substring ( 0 , k ) ) ; } return number ; } }
Find substrings that contain all vowels | c # program to find all substring that contain all vowels ; Returns true if x is vowel . ; Function to check whether a character is vowel or not ; Function to FindSubstrings of string ; To store vowels ; If current character is vowel then insert into hash , ; If all vowels are present in current substring ; Driver Code
using System ; using System . Collections . Generic ; public class GFG { public static bool isVowel ( char x ) { return ( x == ' a ' x == ' e ' x == ' i ' x == ' o ' x == ' u ' ) ; } public static void findSubstring ( string str ) { HashSet < char > hash = new HashSet < char > ( ) ; int start = 0 ; for ( int i = 0 ; i < str . Length ; i ++ ) { if ( isVowel ( str [ i ] ) == true ) { hash . Add ( str [ i ] ) ; if ( hash . Count == 5 ) { Console . Write ( str . Substring ( start , ( i + 1 ) - start ) + " ▁ " ) ; } } else { start = i + 1 ; hash . Clear ( ) ; } } } public static void Main ( string [ ] args ) { string str = " aeoibsddaeiouudb " ; findSubstring ( str ) ; } }
Concatenated string with uncommon characters of two strings | C # program Find concatenated string with uncommon characters of given strings ; Result ; creating a hashMap to add characters in string s2 ; Find characters of s1 that are not present in s2 and append to result ; Find characters of s2 that are not present in s1 . ; Driver code
using System ; using System . Collections . Generic ; class GFG { public static String concatenatedString ( String s1 , String s2 ) { String res = " " ; int i ; Dictionary < char , int > m = new Dictionary < char , int > ( ) ; for ( i = 0 ; i < s2 . Length ; i ++ ) if ( ! m . ContainsKey ( s2 [ i ] ) ) m . Add ( s2 [ i ] , 1 ) ; for ( i = 0 ; i < s1 . Length ; i ++ ) if ( ! m . ContainsKey ( s1 [ i ] ) ) res += s1 [ i ] ; else m [ s1 [ i ] ] = 2 ; for ( i = 0 ; i < s2 . Length ; i ++ ) if ( m [ s2 [ i ] ] == 1 ) res += s2 [ i ] ; return res ; } public static void Main ( String [ ] args ) { String s1 = " abcs " ; String s2 = " cxzca " ; Console . WriteLine ( concatenatedString ( s1 , s2 ) ) ; } }
Count All Palindrome Sub | C # Program to count palindrome substring in a string ; Method which return count palindrome substring ; Iterate the loop twice ; Get each substring ; If length is greater than or equal to two Check for palindrome ; Use StringBuffer class to reverse the string ; Compare substring wih reverse of substring ; return the count ; Swap values of l and r ; Driver Code ; Declare and initialize the string ; Call the method
using System ; class GFG { static int countPS ( String str ) { String temp = " " ; String stf ; int count = 0 ; for ( int i = 0 ; i < str . Length ; i ++ ) { for ( int j = i + 1 ; j <= str . Length ; j ++ ) { temp = str . Substring ( i , j - i ) ; if ( temp . Length >= 2 ) { stf = temp ; stf = reverse ( temp ) ; if ( stf . ToString ( ) . CompareTo ( temp ) == 0 ) count ++ ; } } } return count ; } static String reverse ( String input ) { char [ ] a = input . ToCharArray ( ) ; int l , r = 0 ; r = a . Length - 1 ; for ( l = 0 ; l < r ; l ++ , r -- ) { char temp = a [ l ] ; a [ l ] = a [ r ] ; a [ r ] = temp ; } return String . Join ( " " , a ) ; } public static void Main ( String [ ] args ) { String str = " abbaeae " ; Console . WriteLine ( countPS ( str ) ) ; } }