1 Word Length (4 points)
Topic content:
Your program reads a line of text, separated by a space into several words, to '. ' End. You want to output the length of each word in this line of text. The words here are not language-related, and can include various symbols, such as "it's" to count a word, length 4. Note that there may be contiguous spaces in the row.
Input format:
Enter a line of text in a row to '. ' End, the ending period cannot be counted within the length of the last word.
Output format:
Prints the length of the word for the line text in a row, separated by a space between each length, with no last space at the end of the line.
Input Sample:
It's great to see your here.
Sample output:
4 5 2 3 3 4
time limit: 500ms memory limit: 32000kb
#include <stdio.h> #include <string.h> #include <math.h> #include <stdbool.h>int main (int argc, const char * argv[]) { char C; int index = 0; Char s[200] = {0}; int count = 0; int outputflag = 0; int spaceflag = 0; do{ scanf ("%c", &c); if (c = = ") {if ( Outputflag = = 0 && count>0) { if (spaceflag==1) { printf (" "); } else{ spaceflag = 1; } printf ("%d", count); Count = 0; Outputflag = 1; } } else{ outputflag = 0; count++; } S[index] = C; index++; } while (c!= '. '); if (count-1!=0) { if (spaceflag==1) { printf (""); } else{ spaceflag = 1; } printf ("%d\n", count-1); } return 0;}
2GPS Data Processing (6 points)
Topic content:
The NMEA-0183 protocol is designed to establish a unified BTCM (Maritime Radio Technical Committee) standard in different GPS (Global Positioning System) navigation equipment, by the National Oceanic Electronics Association (nmea-the Nation Marine Electronics Associa-tion) set up a communication protocol. GPS receiver According to the standard specification of the NMEA-0183 protocol, the location, speed and other information through the serial port to the PC, PDA and other equipment.
NMEA-0183 protocol is the standard protocol that GPS receivers should abide by, and also the most widely used protocol in GPS receivers, most common GPS receivers, GPS data processing software, navigation software comply with or at least compatible with this protocol.
The NMEA-0183 protocol defines a lot of statements, but the most commonly used or most compatible statements are $gpgga, $GPGSA, $GPGSV, $GPRMC, $GPVTG, $GPGLL, and so on.
Where the $GPRMC statement is formatted as follows:
$GPRMC, 024813.640,a,3158.4608,n,11848.3737,e,10.05,324.27,150706,,, a*50
Here the entire statement is a line of text, the line with a comma "," separate the fields, the size of each field (length) is different, the example here is only a possibility, and do not think the size of the field as the above example.
Field 0: $GPRMC, statement ID, indicating that the statement recommends minimum location information for recommended Minimum specific gps/transit Data (RMC)
Field 1:UTC time, hhmmss.sss format
Field 2: status, a= positioning, v= not positioned
Field 3: Latitude ddmm.mmmm, Degree fractal format (0 if the number of leading digits is insufficient)
Field 4: Latitude N (north latitude) or S (South latitude)
Field 5: Longitude dddmm.mmmm, Degree format (0 if the number of leading digits is insufficient)
Field 6: Latitude E (longitude) or W (West)
Field 7: Speed, section, knots
Field 8: Bearing angle, Degree
Field 9:UTC date, ddmmyy format
Field 10: Declination, (000-180) degrees (0 if the number of leading digits is insufficient)
Field 11: Declination direction, e= East w= West
Field 16: Checksum value
Here, "*" is the checksum identifier, followed by a checksum of two digits, representing the hexadecimal value of the XOR value of all characters between "$" and "*", excluding both characters. The checksum of the above clause is hexadecimal 50, which is the decimal 80.
Tip: The function of the ^ operator is XOR. The result of a value of 65536 after the remainder of the values of the number of characters between $ and * (the first character and the second character XOR, the result again and the third character Xor, and so on) should be equal to the value of the two hexadecimal digits after the *, otherwise the statement has an error in the transmission. Note that this hexadecimal value will appear in the uppercase letter of the a-f. In addition, if you need to, you can use SSCANF (s, "%d", &i) from the string s to get its expressed integer number to I.
Now your program reads into a series of GPS outputs, which contain $GPRMC and other statements. At the end of the data, there is a single line of
END
Represents the end of the data.
Your program is going to find the $GPRMC statement, calculate the checksum, find out where the checksum is correct, and the field 2 represents the statement that has been positioned, from which the time is calculated and converted into Beijing time. The data will contain multiple $GPRMC statements, with the time of the last statement obtained as the result output.
Your program is bound to read a valid $GPRMC statement.
Input format:
Multiple GPS statements, each ending with a carriage return line. The last line is the end three uppercase letters.
Output format:
6-digit time, expressed as:
Hh:mm:ss
Where HH is a two-digit hour, less than two bits when the front of the 0;mm is a two-digit minute, less than two bits when the front 0;ss is two digits of the second, less than two bits in front of 0.
Input Sample:
$GPRMC, 024813.640,a,3158.4608,n,11848.3737,e,10.05,324.27,150706,,, a*50
END
Sample output:
10:48:13
time limit: 500ms memory limit: 32000kb
#include <stdio.h> #include <string.h> #include <math.h> #include <stdbool.h>int main (int argc, const char * argv[]) {char finalstr[20] = {0}; while (1) {char s[1024]; Gets (s); if (strcmp (S, "END") ==0) {break; }else{char *p1 = STRSTR (S, "$GPRMC"); Char *p2 = STRSTR (S, "*"); if (P1 && p2) {int startIndex = 1; int endindex= (int) (P2-P1-1); Char starts = S[startindex]; int temp = starts; int result = 0; for (int i=startindex+1;i<=endindex;i++) {result = Temp^s[i]; temp = result; } result = result%65536; Char snumber[20]; sprintf (Snumber, "%x", result); Char tnumber[20] = {0}; int j = 0; for (int i=endindex+2;i<strlen (s); i++) { Tnumber[j++] = s[i]; } if (strcmp (Snumber, Tnumber) ==0) {char time[7] = {0}; j = 0; for (int i=7;i<=12;i++) {time[j++] = s[i]; } int hour1 = time[0]-' 0 '; int hour2 = time[1]-' 0 '; int hour = HOUR1*10+HOUR2; hour = hour+8; if (hour>23) {hour = hour-24; } hour1 = HOUR/10; HOUR2 = hour%10; sprintf (Finalstr, "%d%d:", HOUR1,HOUR2); FINALSTR[3] = time[2]; FINALSTR[4] = time[3]; FINALSTR[5] = ': '; FINALSTR[6] = time[4]; FINALSTR[7] = time[5]; }}}} printf ("%s\n", Finalstr);}
Week seventh: pointers and strings