acm oj上一道c语言练习……死活AC不了一直wrong answer求帮助……

2025-01-06 02:50:00
推荐回答(1个)
回答1:

你是否忘记进行行接受(不能直接scanf),或者忘记去除非字母和数字字符。

#include 
#include
int main()
{
    char s[256], *p, *q;
    gets(s);
    for(p=q=s; *p; ++p)
    {
        if(isalpha(*p) || isdigit(*p))
            *q++ = *p;
    }
    *q = '\0';
    for(p=s; *p; ++p)
    {
        if(isupper(*p))
            *p = (*p<='M')*('A'+'M'-*p) + (*p>'M')*('Z'+'N'-*p);
        else if(islower(*p))
            *p = (*p<='m')*('a'+'m'-*p) + (*p>'m')*('z'+'n'-*p);
        else
            *p = '9'+'0'-*p;
    }
    puts(s);
}