-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1.cpp
86 lines (84 loc) · 2.1 KB
/
1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// learn string.compare string.strtok()
#include<iostream>
#include<string>
#include<vector>
using namespace std;
string res;
int convert(string x){
int tempcnt=0;
for(int i=0;i<=x.length();i++){
if(x[i]>='0'&&x[i]<='9')
tempcnt=tempcnt*16+x[i]-'0';
else if(x[i]>='A'&&x[i]<='F')
tempcnt=tempcnt*16+x[i]-'A'+10;
}
return tempcnt;
}
int check(string c){
vector<string> tempstore;
const char b=',';
string s;
string tempori=c;
int loc=0;
while(1){
loc=tempori.find(b);
if(tempori.find(b)==string::npos){
tempstore.push_back(tempori);
break;
}else{
tempstore.push_back(tempori.substr(0,loc));
tempori=tempori.substr(loc+1,tempori.length());
}
}
if(tempstore[0]=="$GPRMC"){
if(tempstore[2]==string(1,'A')){
int checktarget=0;
loc=c.find("*");
tempori=c.substr(loc+1,c.length());
checktarget=convert(tempori);
string cal;
int sum=0;
int calnum=0;
for(int i=c.find('$')+1;i<(int)c.find('*');i++){
cal=c[i];
calnum=(int)c[i];
sum^=calnum;
}
sum=sum%65536;
if(sum==checktarget){
tempori=tempstore[1];
string chour=tempori.substr(0,2);
int ihour=(atoi(chour.c_str())+8)%24;
chour=to_string(ihour);
if (chour.length()==1){
chour='0'+chour;
}
res=chour+':'+tempori.substr(2,2)+':'+tempori.substr(4,2);
return 1;
}else{
tempstore.clear();
return 0;
}
}else{
tempstore.clear();
return 0;
}
}else{
tempstore.clear();
return 0;
}
}
int main(){
string a;
int num=0;
while(1){
getline(cin,a);
if(a=="END"){
break;
}else{
num=check(a);
}
}
cout<<res<<endl;
return 0;
}