1 #include<iostream> 2 #include<string> 3 #define MAX 100 4 using namespace std; 5 bool check(string str1,string str2) 6 { 7 bool flag = true; 8 for(int i=0; i<str1.length(); i++) 9 { 10 if(str1[i]!=str2[str1.length()-1-i]) 11 { 12 flag = false; 13 return flag; 14 } 15 } 16 return flag; 17 } 18 int main(int argc, char* argv[]) 19 { 20 string str[MAX]; 21 int n,a[MAX]; 22 bool flag[MAX]; 23 cin>>n; 24 for(int i=0; i<n; i++) 25 { 26 cin>>str[i]; 27 a[i] = str[i].length(); 28 flag[i] = true; 29 } 30 int num = 0; 31 for(int i=0; i<n; i++) 32 { 33 int len = a[i]; 34 if(flag[i]==true) 35 { 36 for(int j=0;j<n;j++) 37 { 38 if(flag[j]==true&&len==a[j]) 39 { 40 if(check(str[i],str[j])) 41 { 42 num++; 43 flag[i] = false; 44 flag[j] = false; 45 break; 46 } 47 } 48 } 49 } 50 } 51 for(int i=0; i<n; i++) 52 cout<<str[i]<<' '; 53 cout<<endl; 54 cout<<"The Number of Matched String Is: "<<num<<endl; 55 getchar(); 56 getchar(); 57 return 0; 58 }