I love china,I love Beijing.
I U
U love china, U love Beijing.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include<iostream> using namespace std; int main(){ char c[2000]; char a,b; int i=0; do{ c[i]=getchar(); //getchar is a function that takes a single input character from standard input. if(c[i]!='\n')i++; }while(c[i]!='\n'); cin>>a>>b; for (int k = 0; k <i ; ++k) { if(c[k]==a)c[k]=b; } for(int j=0;j<i;j++){ cout<<c[j]; } return 0; } |
一串字符如果从左读和从右读完全相同,我们称之为回文
例如:qwerty 输出:no 例如:qwerewq 输出:yes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include<iostream> using namespace std; int main(){ char c[2000]; int i=0,j=0; do{ c[i]=getchar(); if(c[i]!='\n') i++; }while(c[i]!='\n'); while(c[j]==c[i-1-j]) { j++; if(j>i/2)break; } if(j>i/2)cout<<"YES"; else cout<<"NO"; return 0; } |