code.club

標題: 判斷迴文句或鏡像句的笨方法 [打印本頁]

作者: enter    時間: 2015-10-19 18:08
標題: 判斷迴文句或鏡像句的笨方法
本帖最後由 enter 於 2015-10-19 18:17 編輯

#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
                               
        string str;
        int j,b=1,m=1,len;
    cin>>str;
        len=str.length()-1;
       
        for(j=0;j<str.length();j++){
         if(str[j]!=str[len-j]) b=0;
         if(str[j]>90||str[j]=='B'||str[j]=='C'||str[j]=='D'||str[j]=='F'||str[j]=='G'||str[j]=='K'||str[j]=='N'||str[j]=='P'||str[j]=='Q'||str[j]=='R'||str[j]=='4'||str[j]=='6'||str[j]=='7'||str[j]=='9') m=0;
}

if(b==0&&m==1) cout<<"This is mirrored string but not palindrome.\n";
if(b==1&&m==0) cout<<"This is  palindrome but  not mirrored string.\n";
if(b==1&&m==1) cout<<"This is both.\n";
if(b==0&&m==0) cout<<"This is nothing.\n";
cout<<b<<endl<<m;
return 0;
}




歡迎光臨 code.club (https://code.club/) Powered by Discuz! X3.2