题意:给你东八区的时间,给你另一个时区,让你求出该时区的时间
条件:1 每个相邻的时区隔一个小时
思路:比东八就按比例加时间,比东八小就按比例减时间
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <list>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int a,b;
char s[100];
scanf("%d%d%s",&a,&b,s);
int x=0,y=0,flag=0,mark,mov=0;
for(int i=0; s[i]!='\0'; i++)
{
if(s[i]=='+')
{
mark=1;
}
else if(s[i]=='-')
{
mark=0;
}
else if(s[i]=='.')
{
flag=1;
}
else if(flag==0&&s[i]>='0'&&s[i]<='9')
{
if(mov!=0)
{
x=x*10+s[i]-'0';
}
else
{
x=s[i]-'0';
mov=1;
}
}
else if(flag==1&&s[i]>='0'&&s[i]<='9')
{
y=s[i]-'0';
}
}
int x1,y1;
if(mark==1)
{
y1=(y*6+b)%60;
if(y*6+b>=60)
{
x1=(a+x-8+1+24)%24;
}
else
{
x1=(a+x-8+24)%24;
}
}
else
{
x=-x;
y1=(b-y*6+60)%60;
if(b-y*6<0)
{
x1=(a+x-8-1+24)%24;
}
else
{
x1=(a+x-8+24)%24;
}
}
printf("%02d:%02d\n",x1,y1);
}
return 0;
}
总结:1 是一道水题,但是今天wa了好多次,没有考虑到我这种计算方式里面正负计算不同。本来是想把小时换成分钟来写的,这样可能就不会犯今天这样的错误了。