| 网站首页 | 业界新闻 | 群组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
 跟大牛学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

Enter a 24-hour time: 13:15
Closest departure time is 12:47 pm ,arriving at 3:00 pm.

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        AM：[00:00:00--11:59:59]
PM：[12:00:00--23:59:59]    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;
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编辑过]     -18.06.21                • 8
• 1/1页
• • 1
• Powered by Discuz, Processed in 0.049224 second(s), 8 queries.