2013年10月24日 星期四

[ZJ] a779: 1. Reversal of Field

a779: 1. Reversal of Field
關鍵字:

通過 : 13 人 /14 次 送出 : 18 人 /56 次 | 通過比率 : 72%
公開 測資點 1 (100%): 1.0s, 64 MB | 評分方式: Tolerant

最近更新 : 2013-10-24 08:00 
內容 :
回文是指一串單字、片語或數字組成的文字,而這串文字由左至右讀和由右至左讀是一樣的 (不含標點符號) 。請你寫一個程式判斷輸入字串是否為回文。 
輸入說明 : 
輸入多個字串。
輸出說明 : 
請重複一次輸入字串,如果是回文請輸出"-- is a palindrome" (不含引號) ,不是則輸出"-- is not a palindrome" (不含引號) 。
範例輸入 : help
Madam, I'm Adam.
12345321
範例輸出 :
Madam, I'm Adam.
-- is a palindrome
12345321
-- is not a palindrome
提示 : 
出處 : 
HP CodeWars 2008 
(管理:snail)
--------------------------------------------------------------------------------------------------------
#include<stdio.h>
#include<iostream>
using namespace std;
char s[1005];
string a;
int main(){
    int i;
    while(gets(s)){
        a.clear();
        for(i=0;s[i];i++){
            if(s[i]<='Z' && s[i]>='A') a+=s[i]-'A'+'a';
            if(s[i]<='z' && s[i]>='a') a+=s[i];
            if(s[i]<='9' && s[i]>='0') a+=s[i];
        }
        int c=1;
        for(i=0;i<a.length();i++)
            if(a[i]!=a[a.length()-i-1])
                c=0;
        puts(s);
        if(c) puts("-- is a palindrome");
        else puts("-- is not a palindrome");
    }
}

沒有留言:

張貼留言