标题:小白求解答,谢谢各位大神。
只看楼主
学C中爱
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2018-4-14
结帖率:50%
已结贴  问题点数:20 回复次数:7 
小白求解答,谢谢各位大神。
初学C,一脸懵逼,能百度的都百度了,如果问题太傻逼(我真的不懂),也请各位大神们解答一下,十分感谢。
第一题:
下面的表格给出一个城市到另一个城市的每日航班信息

起飞时间                抵达时间
8:00 am                  10:16 pm                     
9:43 am                  11:52 pm
11:19 am                 1:31 pm
12:47 am                 3:00 pm
2:00 am                  4:08 pm
3:45 am                  5:55 pm
7:00 am                  9:20 pm
9:45 am                  11:58 pm

编写一个程序,要求用户输入一个时间(用24小时制的时分表示)。程序选择起飞时间与用户输入最接近的航班,显示出相应的起飞时间和抵达时间。
Enter a 24-hour time: 13:15
Closest departure time is 12:47 pm ,arriving at 3:00 pm.

第二题:
用户输入任意个日期,用0/0/0指示输入结束,不再输入日期。
Enter a date (mm/dd/yy):  3/6/08
Enter a date (mm/dd/yy):  5/17/07
Enter a date (mm/dd/yy):  6/3/07
Enter a date (mm/dd/yy):  0/0/0
5/17/07 is the earliest date.


第三题:
编写程序计算句子平均词长。
Enter a sentence: It was deja vu all over again.
Average word length: 3.4
搜索更多相关主题的帖子: 时间 用户 输入 Enter date 
2018-04-14 15:38
螃蟹爱吃小鱼
Rank: 3Rank: 3
等 级:论坛游侠
威 望:2
帖 子:51
专家分:145
注 册:2018-3-6
得分:0 
回复 楼主 学C中爱
楼主第一问起飞时间全是am?看你示例输出有pm啊
2018-04-14 17:06
自学的数学
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:46
帖 子:967
专家分:4146
注 册:2017-11-15
得分:0 
AM:[00:00:00--11:59:59]
PM:[12:00:00--23:59:59]
请注意区别。二十四小时制代表数字是0到23,24点只是指23:59:60(00:00:00)秒那一刻,标准称呼应该是没有24点说法的(也就是没有 24:00:00)。二十四小时制是国际标准时间系统。
2018-04-14 17:17
螃蟹爱吃小鱼
Rank: 3Rank: 3
等 级:论坛游侠
威 望:2
帖 子:51
专家分:145
注 册:2018-3-6
得分:20 
程序一:
将你条件稍微改了一下
起飞时间                抵达时间
8:00 am                  10:16 pm                     
9:43 am                  11:52 pm
11:19 am                 1:31 pm
12:47 pm                 3:00 pm
2:00 pm                  4:08 pm
3:45 pm                  5:55 pm
7:00 pm                  9:20 pm
9:45 pm                  11:58 pm
#include<stdio.h>
void main()
{
    int h,m;
    printf("Enter a 24-hour time :");
    scanf("%d:%d",&h,&m);
    int count;
    count = 60*h+m;
    if(count<=(8*60))
    {
        if((8*60-count)<=(count+2*60+15))
        printf("Closest departure time is 8:00 am ,arriving at 10:16 pm");
        else
            printf("Closest departure time is 9:45 pm ,arriving at 11:58 pm");
    }
    if(count>(8*60)&&count<=(9*60+43))
    {
        if((count-(8*60))<=((9*60+43)-count))
            printf("Closest departure time is 8:00 am ,arriving at 10:16 pm");
        else
            printf("Closest departure time is 9:43 am ,arriving at 11:52 pm");
    }
    if(count>(9*60+43)&&count<=(11*60+19))
    {
        if((count-(9*60+43))<=((11*60+19)-count))
            printf("Closest departure time is 9:43 am ,arriving at 11:52 pm");
        else
            printf("Closest departure time is 11:19 am ,arriving at 1:31 pm");
    }
    if(count>(11*60+19)&&count<=(12*60+47))
    {
        if((count-(11*60+19))<=((12*60+47)-count))
            printf("Closest departure time is 11:19 am ,arriving at 1:31 pm");
        else
            printf("Closest departure time is 12:47 am ,arriving at 3:00 pm");
    }
    if(count>(12*60+47)&&count<=(14*60))
    {
        if((count-(12*60+47))<=((14*60)-count))
            printf("Closest departure time is 12:47 am ,arriving at 3:00 pm");
        else
            printf("Closest departure time is 2:00 pm ,arriving at 4:08 pm");
    }
    if(count>(14*60)&&count<=(15*60+45))
    {
        if((count-(14*60))<=((15*60+45)-count))
            printf("Closest departure time is 2:00 pm ,arriving at 4:08 pm");
        else
            printf("Closest departure time is 3:45 pm ,arriving at 5:55 pm");
    }
    if(count>(15*60+45)&&count<=(19*60))
    {
        if((count-(15*60+45))<=((19*60)-count))
            printf("Closest departure time is 3:45 pm ,arriving at 5:55 pm");
        else
            printf("Closest departure time is 7:00 pm ,arriving at 9:20 pm");
    }
    if(count>(19*60)&&count<=(21*60+45))
    {
        if((count-(19*60))<=((21*60+45)-count))
            printf("Closest departure time is 7:00 pm ,arriving at 9:20 pm");
        else
            printf("Closest departure time is 9:45 pm ,arriving at 11:58 pm");
    }
    if(count>21*60+45)
        printf("Closest departure time is 9:45 pm ,arriving at 11:58 pm");
}
程序二:
#include<stdio.h>
void main()
{
    int day,month,year;
    printf("输入日期:");
    scanf("%d/%d/%d",&month,&day,&year);
    int min_day,min_month,min_year;
    min_day = day;
    min_month = month;
    min_year =year;
    while(day!=0||month!=0||year!=0)
    {
        if(year<min_year)
        {
            min_day = day;
            min_month = month;
            min_year =year;   
        }
        if(year==min_year)
        {
            if(month<min_month)
            {
                min_day = day;
                min_month = month;
            }
            if(month==min_month)
            {
                if(day<min_day)
                    min_day = day;
            }
        }
        scanf("%d/%d/%d",&month,&day,&year);   
    }
    printf("%d/%d/%02d is the earliest date\n",min_month,min_day,min_year);
}
程序三:
#include<stdio.h>
#include <string.h>
void main()
{
    char str[100];
    int i;
    int count = 0;
    int x = 0;
    float ave;
    bool flag = false;
    printf("Enter a sentence:");
    gets(str);
    for(i = 0; i<100; i++)
    {
        if(str[i]=='\0')
            break;
        if((str[i]>='a'&&str[i]<='z')||(str[i]>='A'&&str[i]<='Z'))
        {
            count++;
            flag = true;
        }
        else
        {
            if(flag)
                x++;
        }
    }
    ave=float(count)/x;
    printf("%f\n",ave);
}

[此贴子已经被作者于2018-4-14 20:44编辑过]

2018-04-14 17:41
nosnoy
Rank: 9Rank: 9Rank: 9
来 自:mcu
等 级:贵宾
威 望:14
帖 子:540
专家分:1158
注 册:2016-9-17
得分:0 
第二题

先判断年份  大就存新日期  小则忽略
再依次判断月份 日期

第三题
把 字符串 变成数组存储,检测空格 再重新计数
最后算平均值

穷举是最暴力的美学
2018-04-14 18:18
学C中爱
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2018-4-14
得分:0 
回复 4楼 螃蟹爱吃小鱼
十分感谢您的解答。
2018-04-15 13:24
学C中爱
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2018-4-14
得分:0 
回复 3楼 自学的数学
嗯,谢谢您的提醒
2018-04-15 13:26
学C中爱
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2018-4-14
得分:0 
回复 5楼 nosnoy
谢谢您的解答
2018-04-15 13:27



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




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

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