| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1106 人关注过本帖, 1 人收藏
标题:我不知道为什么进不了循环
只看楼主 加入收藏
王思源
Rank: 1
等 级:新手上路
帖 子:33
专家分:1
注 册:2012-9-16
结帖率:60%
收藏(1)
已结贴  问题点数:30 回复次数:17 
我不知道为什么进不了循环
这个是题目
Your roommate is not very familiar with Chinese Railway, and always get confused what the train number means. Now it's time to help him out.
In China, train number contains a lot of information. In this problem, you are supposed to answer the type of train. Train numbers are mainly numbered in following rules:
1. In this problem, you are given a train number containing 2~5 character, where the first character can be either digits or upper-case letter, and other characters are all digits.
2. If the first character is a letter, the train type is determined by the first letter:
'K': Rapid
'T' or 'Q': Express
'Z': SuperExpress
'D': EMUExpress
'G' or 'C': HighSpeed
3. If the first character is a digit, the train type is determined by the integer S the train number forms. To simplify the problem, you may assume:
1000 <= S < 6000: Semi-fast
S >= 6000: Local
And you may assume that no test case will contain any string that was not mentioned in the description.
Input
First line: number of test cases T;
2 ~ T+1 line: Train number.
Output
For each case, output the train type described before.
ATTENTION: Don't modify the names, or you will get WA, copying and pasting them are strongly recommended.
Sample Input
3
4419
Z61
G101

Sample Output
Semi-fast
SuperExpress
HighSpeed


这是我的程序
int main(int argc, char* argv[])
{   
    int m,i;
    char c;
    scanf("%d",&m);

    for(i=1;i<=m;i++)//我的问题是为什么进不去循环啊
    {
        getchar(c);
        switch(c)
        {
           case 'K':printf("Rapid");break;
           case 'T':case 'Q':printf("Express");break;
           case 'Z':printf("SuperExpress");break;
           case 'D':printf("EMUExpress");break;
           case 'G':case 'C':printf("HighSpeed");break;

           case '1':case '2':case '3':case '4':case '5':case '6':printf("Semi-fast"); break;
           default:printf("Local");
        }
        
    }
    return 0;
}
搜索更多相关主题的帖子: familiar following character train Chinese 
2012-11-07 14:05
hejian11
Rank: 2
等 级:论坛游民
帖 子:35
专家分:49
注 册:2012-10-23
收藏
得分:20 
现在可以了,你看看吧!对了,记得在循环中用输入流记得要FFLUSH函数进行缓存处理!

#include <stdio.h>

int main(int argc, char* argv[])
{   
    int m,i;
    char c;
    scanf("%d",&m);
    fflush(stdin);
    for(i=1;i<=m;i++)//我的问题是为什么进不去循环啊
    {
        c=getchar();
        fflush(stdin);
        printf("c: %c\n",c);
        switch(c)
        {
           case 'K':printf("Rapid");break;
           case 'T':case 'Q':printf("Express");break;
           case 'Z':printf("SuperExpress");break;
           case 'D':printf("EMUExpress");break;
           case 'G':case 'C':printf("HighSpeed");break;

           case '1':case '2':case '3':case '4':case '5':case '6':printf("Semi-fast"); break;
           default:printf("Local\n");
        }
        
    }
    return 0;
}
2012-11-07 14:46
yaobao
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:4
帖 子:1854
专家分:4121
注 册:2012-10-25
收藏
得分:0 
回复 楼主 王思源
学习了,谢谢

认认真真的学习,踏踏实实的走路:戒骄戒躁!!!
2012-11-07 16:04
zxd543
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:内蒙古
等 级:贵宾
威 望:17
帖 子:453
专家分:2351
注 册:2012-4-12
收藏
得分:0 
c=getchar();
switch(c)
感觉这样改就行呢没测试

马马虎虎 不吝赐教 我是路过蹭分滴
2012-11-07 21:22
一个孩子
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:5
帖 子:356
专家分:954
注 册:2012-10-1
收藏
得分:3 
程序代码:
#include <stdio.h>

int main(int argc, char* argv[])
{  
    int m,i;
    char c;
    scanf("%d",&m);
    getchar();//接收回车符
    //fflush(stdin);
    for(i=1;i<=m;i++)//我的问题是为什么进不去循环啊
    {
        c=getchar();//接收字符
        //fflush(stdin);
        printf("c: %c\n",c);
        getchar();//接收回车符,它接收的是c=getchar();后你敲的回车符
        switch(c)
        {
           case 'K':printf("Rapid\n");break;
           case 'T':case 'Q':printf("Express");break;
           case 'Z':printf("SuperExpress");break;
           case 'D':printf("EMUExpress");break;
           case 'G':case 'C':printf("HighSpeed");break;

           case '1':case '2':case '3':case '4':case '5':case '6':printf("Semi-fast"); break;
           default:printf("Local\n");
        }
       
    }
    return 0;
} 

重要的不是结果,是求一个结果的过程,哪怕千难万难,当你有想要的结果时,你已走的很远
2012-11-07 22:02
王思源
Rank: 1
等 级:新手上路
帖 子:33
专家分:1
注 册:2012-9-16
收藏
得分:0 
回复 楼主 王思源
真是太感谢啦!真的可以了
不过我还是没懂为什么一定要这样啊,我怎么觉得以前没有听说过也没有用过啊??
2012-11-07 22:04
王思源
Rank: 1
等 级:新手上路
帖 子:33
专家分:1
注 册:2012-9-16
收藏
得分:0 
回复 2楼 hejian11
真是太感谢啦!真的可以了
不过我还是没懂为什么一定要这样啊,我怎么觉得以前没有听说过也没有用过啊??
2012-11-07 22:05
hejian11
Rank: 2
等 级:论坛游民
帖 子:35
专家分:49
注 册:2012-10-23
收藏
得分:0 
是说那个缓存问题吗?那是因为你多次进行输入操作的话,用scanf或者getchar的话他是先放入缓存的,还不懂的话就百度下fflush!
2012-11-08 09:59
hfhf2006
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:62
专家分:169
注 册:2012-6-29
收藏
得分:0 
回复 楼主 王思源
进步了循环吗,可以啊,我在vc中用debug调试的。
2012-11-08 11:25
王思源
Rank: 1
等 级:新手上路
帖 子:33
专家分:1
注 册:2012-9-16
收藏
得分:0 
回复 5楼 一个孩子
为什么要接收回车呢?scanf中不是回车可以表示输入结束吗?
2012-11-08 14:46
快速回复:我不知道为什么进不了循环
数据加载中...
 
   



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

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