标题:C++里如果忽略大小写问题
只看楼主
ciappcia
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2008-6-7
得分:0 
#include <iostream>
#include <cstring>
using namespace std;

bool isPalindrome(const char *);

int main() {
    char i='a',j='A';
    cout<<(int)i<<(int)j;
    cout << "Enter a string:";
    char s[80];
    cin.getline(s, 80);
    if(isPalindrome(s))
        cout << s << " is a palindrome" << endl;
    else
        cout << s << " is not a palindrome" << endl;
    
    return 0;
}

bool isPalindrome(const char * const s)
{
    int low = 0;
    int high = strlen(s) - 1;
    
    while (low < high)
    {
        if (s[low] != s[high]&&(s[low]+32!=s[high])&&(s[low]-32!=s[high]))
            return false;
        low++;
        high--;
    }
    
    return true;
}
2008-11-08 19:37



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-242644-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.726453 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved