1 条题解

  • 0
    @ 2024-12-24 9:49:24

    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;
     }
    

    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
    899
    时间
    3000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者