/* 实现功能:判断输入的字符是否为回文 即正序字符与反序字符一样 例如:leeeeeeeel */ #include <iostream> using namespace std; void main() { int i; int j = 0; int nType = 0; char str[10]; char temp[10]; cout << "please input string:" << endl; for( i = 0; i < 10; i++ ) cin >> str[i]; for( i = sizeof(str); i >= 0; i-- ) { if( j < sizeof(temp) ) { if( i == sizeof(str) ) { temp[sizeof(temp)] = str[i]; } else { temp[j] = str[i]; j++; } } } for( i = 0; i < 10; i++ ) { if( str[i] != temp[i] ) { nType = 1; break; } } cout << "正序字符:" << endl; for( i = 0; i < sizeof(str); i++ ) { cout << str[i]; } cout << endl << "反序字符:" << endl; for( j = 0; j < sizeof(temp); j++ ) { cout << temp[j]; } cout << endl; if( nType != 0 ) { cout << "最终判定结果:非回文" << endl; } else { cout << "最终判定结果:回文" << endl; } }
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课
#include <stdio.h>#include <string.h>main(){ char a[]="5leael5"; int length = strlen(a); int i; int ret = 1; for(i=0;i<(length/2);i++) { if ( a != a[length-1-i]) { ret = 0; continue; } } if(ret) puts("is huiwen"); else puts("is not huiwen");}