text: Check if string is right to left diagonal or not | C ++ program to Check if the given string is right to left diagonal or not ; Function to check if the given string is right to left diagonal or not ; Iterate over string ; If character is not same as the first character then return false ; Driver Code ; Given String str ; Function Call
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; int is_rtol ( string s ) { int tmp = sqrt ( s . length ( ) ) - 1 ; char first = s [ tmp ] ; for ( int pos = tmp ; pos < s . length ( ) - 1 ; pos += tmp ) { if ( s [ pos ] != first ) { return false ; } } return true ; } int main ( ) { string str = " abcxabxcaxbcxabc " ; if ( is_rtol ( str ) ) { cout << " Yes " << endl ; } else { cout << " No " << endl ; } return 0 ; }