Count of character pairs at same distance as in English alphabets | A Simple C ++ program to find pairs with distance equal to English alphabet distance ; Function to count pairs ; Increment count if characters are at same distance ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countPairs ( string str ) { int result = 0 ; int n = str . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) if ( abs ( str [ i ] - str [ j ] ) == abs ( i - j ) ) result ++ ; return result ; } int main ( ) { string str = " geeksforgeeks " ; cout << countPairs ( str ) ; return 0 ; }