标题:UVa 401,我自己运行测试数据都没有问题,但 UVa 的回复是编译错误
只看楼主
魏则西
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2014-8-26
结帖率:0
 问题点数:0 回复次数:1 
UVa 401,我自己运行测试数据都没有问题,但 UVa 的回复是编译错误
Palindromes

A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDEDCBA" is a palindrome because it is the same when the string is read from left to right as when the string is read from right to left.


A mirrored string is a string for which when each of the elements of the string is changed to its reverse (if it has a reverse) and the string is read backwards the result is the same as the original string. For example, the string "3AIAE" is a mirrored string because "A" and "I" are their own reverses, and "3" and "E" are each others' reverses.


A mirrored palindrome is a string that meets the criteria of a regular palindrome and the criteria of a mirrored string. The string "ATOYOTA" is a mirrored palindrome because if the string is read backwards, the string is the same as the original and because if each of the characters is replaced by its reverse and the result is read backwards, the result is the same as the original string. Of course, "A", "T", "O", and "Y" are all their own reverses.


A list of all valid characters and their reverses is as follows.


Character     Reverse     Character     Reverse     Character     Reverse
A     A     M     M     Y     Y
B         N         Z     5
C         O     O     1     1
D         P         2     S
E     3     Q         3     E
F         R         4     
G         S     2     5     Z
H     H     T     T     6     
I     I     U     U     7     
J     L     V     V     8     8
K         W     W     9     
L     J     X     X         


Note that O (zero) and 0 (the letter) are considered the same character and therefore ONLY the letter "0" is a valid character.

Input
Input consists of strings (one per line) each of which will consist of one to twenty valid characters. There will be no invalid characters in any of the strings. Your program should read to the end of file.

Output
For each input string, you should print the string starting in column 1 immediately followed by exactly one of the following strings.


STRING    CRITERIA
" -- is not a palindrome."     if the string is not a palindrome and is not a mirrored string
" -- is a regular palindrome."     if the string is a palindrome and is not a mirrored string
" -- is a mirrored string."     if the string is not a palindrome and is a mirrored string
" -- is a mirrored palindrome."     if the string is a palindrome and is a mirrored string

Note that the output line is to include the -'s and spacing exactly as shown in the table above and demonstrated in the Sample Output below.

In addition, after each output line, you must print an empty line.

Sample Input

NOTAPALINDROME
ISAPALINILAPASI
2A3MEAS
ATOYOTA

Sample Output

NOTAPALINDROME -- is not a palindrome.
 
ISAPALINILAPASI -- is a regular palindrome.
 
2A3MEAS -- is a mirrored string.
 
ATOYOTA -- is a mirrored palindrome.

#include<stdio.h>
#include<string.h>
int palindrome(char *zf);
int mirrored(char *zf);
void output(int re,char *zf);
int main()
{
    char zf[1024];
    int a,b,re;
    while(scanf("%s",zf))
    {
        a=palindrome(zf);//是否是回文 1
        b=mirrored(zf);//是否是镜像 2
        re=a+b;
        output(re,zf);//输出最终结果
        printf("\n\n");
    }
    return 0;
}
int palindrome(char *zf)
{
    char zf1[1024];
    int i,n,pd=0;
    n=strlen(zf);
    for(i=0;i<n;i++)
        zf1[i]=zf[n-1-i];
    zf1[n]='\0';
    i=0;
    while(zf[i]!='\0')
    {
        if(zf[i]!=zf1[i])
        {
            pd=1;
            break;
        }
        i++;
    }
    if(pd==0)
        return 1;
    else
        return 0;
}
int mirrored(char *zf)
{
    char zf1[1024],ch;
    int i,n,pd=0;
    n=strlen(zf);
    for(i=0;i<n;i++)
    {
        ch=zf[i];
        if(ch=='E')
            ch='3';
        else if(ch=='3')
            ch='E';
        else if(ch=='J')
            ch='L';
        else if(ch=='L')
            ch='J';
        else if(ch=='S')
            ch='2';
        else if(ch=='2')
            ch='S';
        else if(ch=='Z')
            ch='5';
        else if(ch=='5')
            ch='Z';
        else ;
        zf1[i]=ch;
    }
    zf1[n]='\0';
    i=0;
    while(zf[i]!='\0')
    {
        if(zf[i]!=zf1[i])
        {
            pd=1;
            break;
        }
        i++;
    }
    if(pd==0)
        return 2;
    else
        return 0;
}
void output(int re,char *zf)
{

        if(re==0) printf("%s -- is not a palindrome.",zf);
        else if(re==1) printf("%s -- is a regular palindrome.",zf);
        else if(re==2) printf("%s -- is a mirrored string.",zf);
        else printf("%s -- is a mirrored palindrome.",zf);
   
}

这是UVa一道题和我的代码,我在自己的电脑上运行没有问题,可UVa的回复是编译错误
搜索更多相关主题的帖子: backward regular because example forward 
2014-09-28 20:10
erty1001
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:4
帖 子:331
专家分:1433
注 册:2014-8-31
得分:0 
简单说说:
    if(pd==0)
        return 2;
    else
        return 0;

去掉后面的else
这个else语句 会使编译器误以为不是所有的分支都有return
2014-09-28 20:16



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




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

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