7-2 然后是几点

7-2 然后是几点
当然了,我改完也是错的,因为只需把%04d改为%d就是标准答案了,哈哈

//这是第一遍写的代码,结果平台没给我过
//1120 110
//1310
#include
int nowTime(int oldtime, int minutes);
int main(){
	int oldtime = 0;
	int minutes = 0;
	
	printf("now time is :  %04d\n",oldtime);
	printf("please input time: \n");
	scanf("%d",&oldtime);
	printf("please input minutes: \n");
	scanf("%d",&minutes);
	oldtime = nowTime(oldtime, minutes);
	printf("now time is : %04d",oldtime);
} 

int nowTime(int oldtime, int minutes){
	//			 1120        110
	int oldm = 0;		//老分钟 
	int oldh = 0;		//老小时 
	int addm = 0;		//加分钟 
	int addh = 0;		//加小时 
	addh = minutes / 60;
	addm = minutes % 60;
	oldh = oldtime / 100;
	oldm = oldtime % 100;
	
	oldm = oldm + addm;
	if(oldm > 60){
		oldm = oldm - 60;
		oldh++;
	}else if(oldm = 60){
		oldm = 0;
		oldh++;	
	} 
	
	oldh = addh + oldh;
	if((oldh) > 24){
		oldh = oldh - 24;
	}
	
	oldtime = oldh * 100 + oldm;
	return oldtime;
	
	
}
//这是上网上找的,
//发现一个错误,我给改了几笔
//他这个没改前是输入2359 3 变成2402
//但是他没改前代码,平台认定可以,心酸,我哭
#include 
#include 
int main (void)
{
	int start, min1;
	int min2, time;
	int end;
	int end_h = 0;
	int end_m = 0;
	scanf("%d%d", &start, &min1);
	//计算start表示的时间距离00:00有多少分钟,将小时数转换为分钟,避免出现未进位的情况
	min2 = start / 100 * 60 + start % 100;
	time = min2 + min1;
	end = time / 60 *100 + time % 60;
	end_h = end / 100;
	end_m = end % 100;
	if(end_h >= 24){
		end = (end_h - 24) * 100 + end_m;
	}
	printf ("%04d", end);
}


你可能感兴趣的:(7-2 然后是几点)