69,371
社区成员
发帖
与我相关
我的任务
分享
S
S
S // k = 2, start from here, default: S
W // default: W
I // default: I
L // case 'L': not printed
T // default: T
E // case 'E' then case 'L': not printed
C // default: C
H // default: H
1 // case '1': break switch, *
- // default: - (- stands for blank space)
\1 // case 1:
// notice here: != is preceded than =, and logical result 1 for true and 0 for false
// so the while loop by-pass the - \11 W \1
// after the while ends, pass-through the case 9: #
// then pass-through case 'E' the case 'L': continue
- // skipped by the while
\11 // skipped by the while (note: if not skipped it should case 9, \11 is oct of 9)
W // skipped by the while
\1 // while ends here, continue, k++ then skipped
W // default: W
A // case 'A': a
L // case 'L': not printed
L // case 'L': not printed
M // default: M
P // default: P
1 // case '1': break switch, so *
SWITCH* #WaMP*
That's all.
#include <stdio.h>
void main()
{
char str[]="SSSWILTECH1 \1 \11W\1WALLMP1";
int k;
char c;
for(k=2;(c=str[k])!='\0';k++)
{
switch(c)
{
case 'A':putchar('a');continue;
case '1':break; ///关键在这步和下面一步
case 1: while((c=str[++k]!='\1'&&c!='\0')); //这步
case 9:putchar('#');
case 'E':
case 'L': continue;
default:putchar(c);continue;
}
putchar('*');
}
printf("\n");
}
//第一个"*"的输出是因为遇到第一个"1",执行break,跳转到putchar('*');
//"#"的输出是因为while((c=str[++k]!='\1'&&c!='\0'));循环3次以后继续向下执行(switch语句),输出"#".
//直到遇到"continue".
//第二个"*"和第一个道理一样;
void main()
{
char str[]="SSSWILTECH1 \1 \11W\1WALLMP1";
int k;
char c;
for(k=2;(c=str[k])!='\0';k++)
{
switch(c)
{
case 'A':putchar('a');continue;
case '1':break;
case 1:
while((c=str[++k]!='\1'&&c!='\0'))
putchar('0');
case 9:putchar('#');
case 'E':
case 'L': continue;
default:putchar(c);continue;
}
putchar('*');
}
printf("\n");
}