Đệ quy part 4( đo độ dài, ký tự âm, đối xứng)

#include<iostream> using namespace std; #include<string> int STRLEN(char *s,int i=0,int diem=0) { if(s[i]=='\0') return diem; return STRLEN(s,i+1,diem+1); } int diemkytuam(char *s,int i=0,int d=0) { if(i==STRLEN(s)) return d; return diemkytuam(s,i+1,s[i]=='-'?d+=1:d); } char p[50]="abcba"; int k=STRLEN(p)-1; bool doixung(char *s,int i=0,int j=k,bool x=true) { if((i==((k/2)+1))&&(j==((k/2)-1))) return x=s[i]!=s[j]?false:true; return doixung(s,i+1,j-1); } int main() { printf("Nhap Chuoi De Kiem Tra Doi Xung:"); gets(p); int k=diemkytuam(p); cout<<"ky tu am trong chuoi la: "<<k; bool check=doixung(p); if(check==true ) { cout<<"\nChuoi Doi Xung"; } else if(check==false) { cout<<"\nChuoi Ko Doi Xung"; } system("pause"); return 0; }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.