#include
int main()
{
int bjt = 0;
int utc = 0;
printf("请输入BJT时间:");
scanf("%d", &bjt);
if(bjt > 2359 || bjt < 0||bjt%100>=60)
{
printf("时间格式不合法\n");
}
else
{
//北京时间8点以内
if( bjt/100 < 8)
{
utc = 2400 + bjt - 8*100;
printf("%d\n", utc);
}
//北京时间8点以外
else if( bjt/100 >= 8)
{
utc = bjt - 8*100;
if(utc<100)
{
if(utc<10)
{
printf("%s%d\n", "0", utc);
}
else
{
printf("%d\n", utc);
}
}
else
{
printf("%d\n", utc);
}
}
}
getchar();
getchar();
return 0;
}
补充了一下楼上的,忽略的一点。
#include
int main()
{
int hour,minute;
int time;
scanf("%d",&time);
hour=time/100-8;
minute=time%100;
if(hour==0)
{
if(minute>=0&&minute<10)
{
printf("%d",minute);
}
else
{
hour++;
minute=minute%60;
if(minute<10)
printf("%d0%d",hour,minute);
else printf("%d%d",hour,minute);
}
}
else if(hour<0)
{
hour+=24;
if(minute>=0&&minute<10) printf("%d0%d",hour,minute);
else if(minute<60) printf("%d%d",hour,minute);
else
{
hour++;
minute=minute%60;
if(minute<10)
printf("%d0%d",hour,minute);
else printf("%d%d",hour,minute);
}
}
else
{
if(minute>=0&&minute<10)
{
printf("%d0%d",hour,minute);
}
else if(minute<60) printf("%d%d",hour,minute);
else
{
hour++;
minute=minute%60;
if(minute<10)
printf("%d0%d",hour,minute);
else printf("%d%d",hour,minute);
}
}
return 0;
}
你是在看翁恺老师的《程序设计入门--C语言》吧,我也在学哦^_^o~ 努力!
下面的代码是我自己写的,我验证过,但还是可能会有些错误没发现哈
其中ujt<10的部分参考了楼上的答案
附件里有原文件
#include
int main(){
int bjt=0;
int ujt=0;
printf("请输入bjt时间:");
scanf("%d",&bjt);
if(bjt>2359||bjt<0){
printf("错误");
}
else{
if(bjt<=800){
ujt=2400+(bjt-800);
}
else{ujt=bjt-800;
}
if(ujt<10){printf("0%d",ujt);
}
else {printf("%d",ujt);
}
}
return 0;
}
#include
int main()
{
int bjt = 0;
int utc = 0;
printf("请输入BJT时间:");
scanf("%d", &bjt);
if(bjt > 2359 || bjt < 0)
{
printf("时间格式不合法\n");
}
else
{
//北京时间8点以内
if( bjt/100 < 8)
{
utc = 2400 + bjt - 8*100;
printf("%d\n", utc);
}
//北京时间8点以外
else if( bjt/100 >= 8)
{
utc = bjt - 8*100;
if(utc<100)
{
if(utc<10)
{
printf("%s%d\n", "0", utc);
}
else
{
printf("%d\n", utc);
}
}
else
{
printf("%d\n", utc);
}
}
}
getchar();
getchar();
return 0;
}
#include
int main()
{
int h,m,H,M,t,T;
scanf("%d",&t);
h=t/100;
m=t%100;
H=h-8;
M=m%10;
if(H<0){
H=H+24;
if(m/10>0) printf("%d%d",H,m);
else printf("%d0%d",H,m);
}else{
if(H==0){
if(m/10==0) printf("%d",M);
else printf("%d",m);
}else{
if(m/10>0) printf("%d%d",H,m);
else printf("%d0%d",H,m);
}
}
return 0;
}
[nbgao]