6 条题解

  • 4
    @ 2023-8-11 16:53:07

    根本不需要那么麻烦,用scanf输入就可以了

    #include <bits/stdc++.h>
    using namespace std;
    int h,m,s,a,b,c;
    int main()
    {
        scanf("%d:%d:%d\n%d:%d:%d",&h,&m,&s,&a,&b,&c);
        printf("%d",(h*3600+m*60+s)-(a*3600+b*60+c));
        return 0;
    }
    
    • 3
      @ 2023-7-14 21:14:08
      #include <iostream>
      using namespace std;
      int ha,hb,ma,mb,seca,secb,ta,tb,pos;
      string sa,sb;
      int main(){
          cin>>sa>>sb;
          ha=(sa[0]-'0')*10+(sa[1]-'0');
          ma=(sa[3]-'0')*10+(sa[4]-'0');
          seca=(sa[6]-'0')*10+(sa[7]-'0');
          hb=(sb[0]-'0')*10+(sb[1]-'0');
          mb=(sb[3]-'0')*10+(sb[4]-'0');
          secb=(sb[6]-'0')*10+(sb[7]-'0');    
          ta=ha*3600+ma*60+seca;
          tb=hb*3600+mb*60+secb;
          cout<<ta-tb<<endl;
          return 0;
      }
      
      • 3
        @ 2023-7-8 8:52:57

        #include <iostream> #include <string> using namespace std; int main() { string str1, str2; getline(cin, str1); getline(cin, str2); int str1_h = ((str1[0] - 48) * 10 + (str1[1] - 48)) * 3600;//时->秒 int str1_m = ((str1[3] - 48) * 10 + (str1[4] - 48)) * 60;//分->秒 int str1_s = ((str1[6] - 48) * 10 + (str1[7] - 48));//秒 int str1_sum = str1_h + str1_m + str1_s; int str2_h = ((str2[0] - 48) * 10 + (str2[1] - 48)) * 3600;//时->秒 int str2_m = ((str2[3] - 48) * 10 + (str2[4] - 48)) * 60;//分->秒 int str2_s = ((str2[6] - 48) * 10 + (str2[7] - 48));//秒 int str2_sum = str2_h + str2_m + str2_s; cout << str1_sum - str2_sum; return 0; }

        • 3
          @ 2021-8-17 14:33:29

          只要先输入各自的时、分、秒,再统一计算成秒,相减即可 #include <bits/stdc++.h> using namespace std; int a, b, c, sum1, x, y, z, sum2; char t; int main() { cin >> a >> t >> b >> t >> c; cin >> x >> t >> y >> t >> z; sum1 = a * 3600 + b * 60 + c; sum2 = x * 3600 + y * 60 + z; cout << sum1 - sum2; return 0; }

          • 2
            @ 2024-2-1 19:19:30
            #include <bits/stdc++.h>
            using namespace std;
            int h,m,s,a,b,c;
            int main()
            {
                scanf("%d:%d:%d\n%d:%d:%d",&h,&m,&s,&a,&b,&c);
                printf("%d",(h*3600+m*60+s)-(a*3600+b*60+c));
                return 0;
            }
            
            
            • 1
              @ 2024-2-28 20:57:07
              #include<bits/stdc++.h>
              using namespace std;int h,m,s,a,b,c;int main(){scanf("%d:%d:%d\n%d:%d:%d",&h,&m,&s,&a,&b,&c);printf("%d",(h*3600+m*60+s)-(a*3600+b*60+c));}
              
              • 1

              信息

              ID
              101
              时间
              1000ms
              内存
              16MiB
              难度
              1
              标签
              递交数
              113
              已通过
              81
              上传者