1 条题解

  • 0
    @ 2025-4-12 21:45:14

    C :

    #include<stdio.h>
    #include<string.h>
    
    int main()
    {
    	int l,h,m,s,time=0,now=0,i;
    	double v=0,d=0;
    	char t[20];
    	while(gets(t))
    	{
    		h=(t[0]-'0')*10+t[1]-'0';
    		m=(t[3]-'0')*10+t[4]-'0';
    		s=(t[6]-'0')*10+t[7]-'0';
    		now=h*3600+m*60+s;
    		l=strlen(t);
    		if(l==8)
    		{
    			d+=(now-time)*v;
    			printf("%s %.2lf km\n",t,d/1000);
    			time=now;
    		}
    		else
    		{
    			d+=(now-time)*v;
    			time=now;
    			v=t[9]-'0';
    			for(i=10;i<l;i++)
    				v=v*10+t[i]-'0';
    			v/=3.6;
    		}
    	}
    	return 0;
    }
    

    C++ :

    #include<stdio.h>
    #include<string.h>
    
    int main()
    {
    	int l,h,m,s,time=0,now=0,i;
    	double v=0,d=0;
    	char t[20];
    	while(gets(t))
    	{
    		h=(t[0]-'0')*10+t[1]-'0';
    		m=(t[3]-'0')*10+t[4]-'0';
    		s=(t[6]-'0')*10+t[7]-'0';
    		now=h*3600+m*60+s;
    		l=strlen(t);
    		if(l==8)
    		{
    			d+=(now-time)*v;
    			printf("%s %.2lf km\n",t,d/1000);
    			time=now;
    		}
    		else
    		{
    			d+=(now-time)*v;
    			time=now;
    			v=t[9]-'0';
    			for(i=10;i<l;i++)
    				v=v*10+t[i]-'0';
    			v/=3.6;
    		}
    	}
    	return 0;
    }
    

    Pascal :

    program p1028;
    var st,ss,sj:string;
        v2,v1,time2,time1,i,j,k,n,h,m,s:longint;
        newd,d:double;
    begin
      time1:=0; v1:=0; d:=0;
      while not eof do
        begin
    	  readln(st); sj:=st;
          h:=(ord(st[1])-ord('0'))*10+(ord(st[2])-ord('0'));
          m:=(ord(st[4])-ord('0'))*10+(ord(st[5])-ord('0'));
          s:=(ord(st[7])-ord('0'))*10+(ord(st[8])-ord('0'));
    	  time2:=h*3600+m*60+s;
          k:=length(st);
    	  if k=8 then
    	    begin
    	      d:=d+(time2-time1)*v1/3600;
              writeln(st,' ',d:0:2,' km');
    		  time1:=time2;
    	    end
    	  else
               begin
                 d:=d+(time2-time1)*v1/3600;
                 time1:=time2;
    			 val(copy(st,10,k-9),v1)
               end;
         end;
    end.
    
    

    Java :

     
    
    import java.text.DecimalFormat;
    import java.util.Scanner;
    
    public class Main {
    
    	public static void main(String[] args) {
    		Scanner cin = new Scanner(System.in);
    		int speed = 0;
    		float distance = 0;
    		int[] startTime = new int[3];
    		boolean isStart = true;
    		while (cin.hasNextLine()) {
    			String hang = cin.nextLine();
    			int lenght = hang.length();
    			if (lenght <= 8) {
    				String[] ts = hang.split(":");
    				int[] endTime = new int[3];
    				endTime[0] = Integer.parseInt(ts[0]);
    				endTime[1] = Integer.parseInt(ts[1]);
    				endTime[2] = Integer.parseInt(ts[2]);
    				int h = endTime[0] - startTime[0];
    				float m = endTime[1] - startTime[1];
    				int s = endTime[2] - startTime[2];
    				m += ((float) s) / 60f;
    				float ddd = (h + m / 60f) * speed;
    				DecimalFormat fnum = new DecimalFormat("##0.00"); 
    				String re=fnum.format(ddd + distance); 
    				System.out.println(hang+" "+re+" km");
    			} else {
    				String[] re_head = hang.split(" ");
    				String[] ts = re_head[0].split(":");
    				
    				int[] endTime = new int[3];
    				endTime[0] = Integer.parseInt(ts[0]);
    				endTime[1] = Integer.parseInt(ts[1]);
    				endTime[2] = Integer.parseInt(ts[2]);
    				if (!isStart) {
    
    					int h = endTime[0] - startTime[0];
    					float m = endTime[1] - startTime[1];
    					int s = endTime[2] - startTime[2];
    					m += ((float) s) / 60f;
    					float ddd = (h + m / 60f) * speed;
    					distance += ddd;
    				}
    				speed = Integer.parseInt(re_head[1]);
    				startTime[0] = endTime[0];
    				startTime[1] = endTime[1];
    				startTime[2] = endTime[2];
    				isStart=false;
    			}
    			// System.out.println( lenght);
    		}
    
    	}
    
    }
    
    

    Python :

    from sys import stdin
    e=time=v=0.0   
    for a in stdin:
        b=a.split()
        c=map(float,b[0].split(':'))
        now=(c[0]+c[1]/60+(c[2]-1)/3600)
        if len(b)==1:
            e+=(now-time)*v
            print b[0],"%.2f km"%(e)
            time=now
        else:
            e+=(now-time)*v
            time=now
            v=int(b[1])
    
    • 1

    信息

    ID
    1406
    时间
    1000ms
    内存
    32MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者