code.club

 找回密碼
 立即註冊
搜索
查看: 6362|回復: 0
打印 上一主題 下一主題

判斷迴文句或鏡像句的笨方法

[複製鏈接]
跳轉到指定樓層
樓主
發表於 2015-10-19 18:08:02 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
本帖最後由 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;
}
回復

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即註冊

本版積分規則

小黑屋|手機版|Archiver|code.club  

GMT+8, 2024-4-26 22:44 , Processed in 0.077100 second(s), 19 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表