1 条题解

  • 0
    @ 2025-4-7 21:41:51

    C :

    #include<stdio.h>
    #include<string.h>
    int main()
    {
    	int T;
        scanf("%d",&T);
        while(T--)
    	{
    		int s=1,M,n,time,t=0;
            char c[5];
            scanf("%d",&M);
            getchar();
            while(M--)
    		{
    			scanf("%s",c);
                n=strlen(c);
                if(n==2)
    				s*=20;
                if(n==4){
    				scanf("%d",&time);
                    t+=time*60/s;
                 }
                 if(n==3)
                    s/=20;
             }
             printf("%d\n",t);
    	}
        return 0;
    }
    

    C++ :

    #include<iostream>
     #include<string>
     using namespace std;
     int main()
     {
     int n,m,count=0;
     double time=0.0,num;
     int rate(int);
     string s;
     cin>>n;
     while(n--)
     {
     cin>>m;
     while(m--)
     {
     cin>>s;
     if(s=="IN")
     count++;
     else if(s=="OUT")
     count--;
     else
     {
     cin>>num;
     time=time+num/rate(count);
    
     }
    
     }
     cout<<time*60<<endl;
     time=0;
     s="";
     }
     return 0;
     }
     int rate(int x)
     {
     int a=1;
     while(x--)
     {
     a=a*20;
     }
     return a;
     }
    

    Pascal :

    const rate = 20;
    var t,n,i,q,k,time,scale:longint;
        c:char;
    begin
      readln(t);
      for q:=1 to t do begin
        readln(n);
        time:=0;
        scale:=1;
        for i:=1 to n do begin
          read(c);
          if(c = 'I')then begin
            readln;
            scale:=scale*rate;
          end;
          if(c = 'O')then begin
            readln;
            scale:=scale div rate;
          end;
          if(c = 'S')then begin
            read(c,c,c);
            readln(k);
            inc(time,trunc(k/scale*60));
          end;
        end;
        writeln(time);
      end;
    end.
    

    Java :

    import java.util.Scanner;
    public class Main
    {
    	public static void main(String[] args)
    	{
    		Scanner sc=new Scanner(System.in);
    		int T=sc.nextInt();
    		while(T-->0)
    		{
    			int M=sc.nextInt();
    			int realTimes=0;
    			int stayTimes=0;
    			int floor=0;
    			while(M-->0)
    			{
    				String str=sc.next();
    				if(str.equals("IN")){
    					floor++;
    				}else if(str.equals("STAY")){
    					stayTimes=sc.nextInt();
    					stayTimes*=60;
    					realTimes+=stayTimes/(int)Math.pow(20,floor);
    				}else{
    					floor--;
    				}
    			}
    			System.out.println(realTimes);
    		}
    	}
    }
    
    • 1

    信息

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