hdu 6308

怪不得自己一直t,原来是有好多函数自己不会用,学到了

注:时钟问题只需要化为分钟来做,就会简便很多

C/C++中字符串与数值相互转换

#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>

int main()
 {
  std::ios::sync_with_stdio(false);
 
 int T;
  std::cin >> T;
 
 for (int cas = 1; cas <= T; ++cas)
 {
    int sgn;
    int a, b, x, y(0);
  
  std::string s;
   
 std::cin >> a >> b >> s;
   
 sgn = (s[3] == '+' ? 1 : -1);
  
  s = s.substr(4);//将从下标为4一直到字符串结束赋值给新字符串 
 
   if (s.size() > 2) 
{
      y = s.back() - '0';
    
      s.pop_back();
    
      s.pop_back();
    }
   
 x = std::stoi(s);//将字符串转为整数 

  
  int m = (a + 24) * 60 + b;

  
  int c = 80;
  
  int d = sgn * (x * 10 + y);

 int e = d - c;
   
 int f = e * 6;
   
 int g = (m + f) % 1440;

 
   printf("%02d:%02d\n", g / 60, g % 60);
  
}
 
 return 0;
}
			

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值