Today, I found this simple problem in the Baidu programming classroom training exercises wearing a hacker turbid vest.
In order to check whether the input is a number, it times out after the result is written.
However, the method used to replace a string with a number is a result, so I will take a note here.
Case-insensitive swapTime Limit: 1000 MS | memory limit: 65535 kb difficulty: 0
DescriptionA string containing only uppercase and lowercase letters without spaces and line breaks is provided. Replace uppercase letters with lowercase letters, and replace lowercase letters with uppercase letters, and then output the interchangeable strings.
InputThe first row has only one integer m (M <= 10), indicating the number of test data groups.
In the next m row, each line has a string (length cannot exceed 100 ).
OutputThe output string after swapping. Each group of output occupies one line.
Sample Input2 acmaccepted
Sample outputAcmaccepted
Timeout problem report:
# Include <stdio. h> # include <string. h> # include <stdlib. h> int main () {char * n, m, s [27]; int A, I, Len; scanf ("% s", & M ); N = & M; A = atoi (n); if (a) // enter the number {While (A --) {scanf ("% s", S ); len = strlen (s); for (I = 0; I <Len; I ++) {If (s [I]> = 65 & S [I] <= 90) // {printf ("% C ", s [I] + 32);} else if (s [I]> = 97 & S [I] <= 122) // printf ("% C ", s [I]-32); else printf ("\ nerror! \ N ") ;}printf (" \ n ") ;}} else // The input is not a number {printf (" data error! \ N ") ;}return 0 ;}
Program:
If I write it like this, although the result does not time out, it does not feel rigorous.
# Include <stdio. h> # include <string. h> int main () {int m, I, Len; char s [101]; scanf ("% d", & M); While (M --) {scanf ("% s", S); Len = strlen (s); for (I = 0; I <Len; I ++) {If (s [I]> = 65 & S [I] <= 90) // {printf ("% C ", s [I] + 32);} else if (s [I]> = 97 & S [I] <= 122) // printf ("% C ", s [I]-32); else printf ("\ nerror! \ N ") ;}printf (" \ n ") ;}return 0 ;}
Program:
Case-insensitive-convert a "numeric string" to a number