I thought of that before, I thought to do so, find the first letter and then rewrite it in the reverse order, and then find the first one again, but it does not work (
#include <cstdlib> #include <iostream> #include <conio.h> #include <stdio.h> #include <string.h> using namespace std; const int S_BUF = 255; int main(){ char str[S_BUF]; cout<<"input text: "; cin.getline(str,255); unsigned int len = strlen(str); unsigned int i; int x = 0; if(str[0]=='c')x++; for(i = 0 ; i < len; i++ )if(str[i]==' '&&str[i+1]=='c')x++; strrev(str); unsigned int j; int y = 0; if(str[0]=='a')y++; for(j = 0 ; j < len; i++ )if(str[j]==' '&&str[j+1]=='a')y++; cout<<"count words on (a) "<<y<<endl; cout<<"count words on (c) "<<x<<endl; system("pause"); return 0; }