Question Link
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2573
This problem confused the % s and gets () input methods and found no error,
The question is not very difficult.
View Code directly
# Include <stdio. h>
# Include <string. h>
Int main (void)
{
Char s [10];
Int L, I, j, flag;
Int t, n;
Scanf ("% d", & T );
While (t --)
{
Flag = 0;
J = 0;
Scanf ("% d", & N );
Getchar ();
While (n --)
{
Gets (s );
L = strlen (s );
If (L = 1)
{
If (FLAG)
Printf ("% C", s [0]-32 );
Else
Printf ("% C", s [0]);
}
Else if (L = 4)
{
Flag =! Flag;
}
Else
{
If (FLAG)
Printf ("% C", s [6]);
Else
Printf ("% C", s [6]-32 );
}
}
Printf ("\ n ");
}
Return 0;
}
If you are familiar with ssscanf (), you can do the same.
# Include <stdio. h>
# Include <string. h> int main () {int t, n, I, K; char a [2, 110] [10]; char B [10], C [10]; scanf ("% d", & T); While (t --) {scanf ("% d", & N); getchar (); for (I = 0; I <n; I ++) {gets (A [I]);} k = 0; for (I = 0; I <n; I ++) {sscanf (A [I], "% [^]", B); sscanf (A [I], "% * S % s", C ); if (strcmp (B, "Caps") = 0) {k ++; continue;} else if (strcmp (B, "shift") = 0) {If (K % 2 = 0) printf ("% C", C [0]-32); else printf ("% C", C [0]);} else if (K % 2 = 0) printf ("% s", B); else if (K % 2 = 1) printf ("% C ", B [0]-32);} printf ("\ n");} return 0 ;}
HDU-2573-Typing