pat-bl-1029
2017-01-20 string traversal & comparison Pit point: The last Test point of the bad key at the end, if the loop out of the condition write a problem (for example, to traverse the end of the string 2) will be an error
/** * pat-bl-1029 * 2017-01-20 * C version/#include <stdio.h> #include <string.h> int main () {Freopen
("In.txt", "R", stdin);
Char str1[100], str2[100];
int alp[26] = {0}, num[10] = {0}, _flag = 0;//is the symbol scanf ("%s", STR1) that the letters, numbers, and underscores are broken;
scanf ("%s", str2);
printf ("strlen (str1) =%lu\n", strlen (STR1));
char test1 = ' a ', test2 = ' a ';
printf ("A:%d, a:%d\n", Test1, test2);
Turn lowercase in two strings to uppercase letters for (int i = 0;i < strlen (str1); i++) {if (str1[i] <= ' z ' && str1[i] >= ' a ')
{Str1[i]-= 32; for (int i = 0;i < strlen (str2); i++) {if (str2[i] <= ' z ' && str2[i] >= ' a ') {str2
[i]-= 32;
}//printf ("str1 =%s, str2 =%s\n", str1, str2);
Traversal string 1, compared to the current character of String 2, if equal, the two current positions are moved back, continuing to compare; otherwise the output of the bad key//Note that the loop control condition should be string 1 end rather than string 2, or it will cause the bad key at the end of the string to not be judged int j = 0;
for (int i = 0, j = 0;i < strlen (str1); i++) {if (str1[i] = = Str2[j] && J < strlen (str2)) {j + +; else {if (Str1[i] <= ' 9 ' && str1[i] >= ' 0 ') {if (Num[str1[i]-' 0 '] = = 0)//The Bad key
The first occurrence, the output of bad keys, and set a flag bit of 1 {printf ("%c", Str1[i]);
Num[str1[i]-' 0 ' = 1;
Or else if (str1[i] = = ' _ ') {if (_flag = = 0) {printf ("_");
_flag = 1;
{else if (Str1[i] <= ' Z ' && str1[i] >= ' a ') {if (Alp[str1[i]-' A '] = = 0)
{printf ("%c", Str1[i]);
Alp[str1[i]-' A '] = 1;
}}//else End} putchar (' \ n '); }
-fin-