qq_31586711
qq_31586711
采纳率0%
2015-09-25 11:03 阅读 2.2k

新手求助,关于switch-case的问题

题目要求如下:
无线电台的RS制信号报告是由三两个部分组成的:
R(Readability) 信号可辨度即清晰度.
S(Strength) 信号强度即大小.
其中R位于报告第一位,共分5级,用1—5数字表示.
Unreadable
Barely readable, occasional words distinguishable
Readable with considerable difficulty
Readable with practically no difficulty
Perfectly readable
报告第二位是S,共分九个级别,用1—9中的一位数字表示
Faint signals, barely perceptible
Very weak signals
Weak signals
Fair signals
Fairly good signals
Good signals
Moderately strong signals
Strong signals
Extremely strong signals
现在,你的程序要读入一个信号报告的数字,然后输出对应的含义。如读到59,则输出:

Extremely strong signals, perfectly readable.

输入格式:
一个整数,信号报告。整数的十位部分表示可辨度,个位部分表示强度。输入的整数范围是[11,59]中的个位不为0的数字,这个范围外的数字不可能出现在测试数据中。

输出格式:
一句话,表示这个信号报告的意义。按照题目中的文字,先输出表示强度的文字,跟上逗号和空格,然后是表示可辨度的文字,跟上句号。注意可辨度的句子的第一个字母是小写的。注意这里的标点符号都是英文的。

输入样例:
33

输出样例:
Weak signals, readable with considerable difficulty.
时间限制:500ms内存限制:32000kb

我的代码如下:

#include
int main()
{
int rs,r = 0,s = 0;
char*a,*b;
scanf("%d",&rs);
s = rs % 10;
if (s != 0)
{

    if (rs >= 11 && rs <= 59 )
    {
        r = rs / 10;
        s = rs % 10;
        switch (r)
        {
            case 1:
                a = "Unreadable";
                break;
            case 2:
                a = "Barely readable, occasional words distinguishable";
                break;
            case 3:
                a = "Readable with considerable difficulty";
                break;
            case 4:
                a = "Readable with practically no difficulty";
                break;
            case 5:
                a= "Perfectly readable";
                break;
        }
        switch (s)
        {
            case 1:
                b = "faint signals, barely perceptible.";
                break;
            case 2:
                b = "very weak signals.";
                break;
            case 3:
                b = "weak signals.";
                break;
            case 4:
                b = "fair signals.";
                break;
            case 5:
                b = "fairly good signals.";
                break;
            case 6:
                b = "good signals.";
                break;
            case 7:
                b = "moderately strong signals.";
                break;
            case 8:
                b = "strong signals.";
                break;
            case 9:
                b = "extremely strong signals.";
                break;
        }

        printf("%s, %s",a,b);

    }

}
return 0;

}

为何在线测试无法通过,求指教。谢谢。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • qq_31586711 qq_31586711 2015-09-25 11:24
     #include <stdio.h>
    int main()
    {
        int rs, r = 0, s = 0;
        char *a,*b;
        scanf("%d", &rs);
        s = rs % 10;
        if (rs >= 11 && rs <= 59 && s != 0)
        {
            r = rs / 10;
            s = rs % 10;
            switch (r)
            {
                case 1:
                a = "Unreadable";
                break;
                case 2:
                a = "Barely readable,occasional words distinguishable";
                break;
                case 3:
                a = "Readable with considerable difficulty";
                break;
                case 4:
                a = "Readable with practically no difficulty";
                break;
                case 5:
                a = "Perfectly readable";
                break;
            }
            switch (s)
            {
                case 1:
                b = "faint signals,barely perceptible";
                break;
                case 2:
                b = "very weak signals";
                break;
                case 3:
                b = "weak signals";
                break;
                case 4:
                b = "fair signals";
                break;
                case 5:
                b = "fairly good signals";
                break;
                case 6:
                b = "good signals";
                break;
                case 7:
                b = "moderately strong signals";
                break;
                case 8:
                b = "strong signals";
                break;
                case 9:
                b = "extremely strong signals";
                break;
            }
    
            printf("%s, %s.", a, b);
    
        }
        return 0;
    
    }
    
    点赞 评论 复制链接分享
  • Marksinoberg 泰 戈 尔 2016-09-21 05:29

    楼上的那个代码足够了。s

    点赞 评论 复制链接分享

相关推荐