程序代码:
char* foo( char* s ) { for( char* p=s; *p; ++p ) { if( *p>='A' && *p<='Z' ) *p = (*p - 'A' + 4)%26 + 'a'; else if( *p>='a' && *p<='z' ) *p = (*p - 'a' + 4)%26 + 'A'; } return s; } #include <string.h> #include <assert.h> int main( void ) { char s1[] = "China"; assert( strcmp(foo(s1),"gLMRE") == 0 ); char s2[] = "azAZ"; assert( strcmp(foo(s2),"EDed") == 0 ); }