转换和朋友 [英] switch and friends

查看:86
本文介绍了转换和朋友的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿人,

有人可以解释一下这个片段是如何工作的吗?我在一场比赛中遇到了这个问题,这个问题在

时间真是空白。

实际上我后来跟踪了这个程序,但是我仍然怀疑为什么编译器似乎忽略了case,default ..。关键字。谢谢

预付款。


#include< stdio.h>


void func()/ *经过一些追踪后我的代码* /

{

char str [] =" ++ c dna c evol I" ;;

int sz = sizeof(str)/ sizeof(char);

int i = sz-1;

printf(" \ n");

开关(8)

{

案例2:while(i)

{

默认值:printf("%c",str [i--]);}

}

}

int main()

{

int i = 0;

/ *实际代码在比赛* /

开关(0)

{

案例1:for(; i< 5; i ++)

case 10:{printf("%d",i);

while(i%3!= 0)

case 5:printf("%) d",++ i);

默认值:printf(" *");

}

}

printf(" \ n\\\
\ n");

func();

scanf("%d");

返回0;

}

Hey people,
Can somebody explain me how this fragment works ? I came across
this question in a competition and was really blank about this at the
time.
Actually I traced the program later but I still have doubts as to why
the compiler seems to neglect "case, default .. " keywords. Thanks in
advance.

#include <stdio.h>

void func() /*Code by me after some tracing */
{
char str[] = " ++c dna c evol I";
int sz = sizeof(str)/sizeof(char);
int i=sz-1;
printf("\n");
switch(8)
{
case 2:while(i)
{
default:printf("%c",str[i--]);}
}
}
int main()
{
int i=0;
/* Actual code in competition */
switch(0)
{
case 1: for(;i<5;i++)
case 10:{ printf("%d",i);
while(i%3!=0)
case 5: printf("%d",++i);
default: printf("*");
}
}
printf("\n\n\n");
func();
scanf("%d");
return 0;
}

推荐答案

gopala写道:
gopala wrote:

嘿人,

有人可以解释一下这个片段是如何工作的吗?我在一场比赛中遇到了这个问题,这个问题在

时间真是空白。

实际上我后来跟踪了这个程序,但是我仍然怀疑为什么编译器似乎忽略了case,default ..。关键字。谢谢

预付款。


#include< stdio.h>


void func()/ *经过一些追踪后我的代码* /

{

char str [] =" ++ c dna c evol I" ;;

int sz = sizeof(str)/ sizeof(char);

int i = sz-1;

printf(" \ n");

开关(8)

{

案例2:while(i)

{

默认值:printf("%c",str [i--]);}

}

}
Hey people,
Can somebody explain me how this fragment works ? I came across
this question in a competition and was really blank about this at the
time.
Actually I traced the program later but I still have doubts as to why
the compiler seems to neglect "case, default .. " keywords. Thanks in
advance.

#include <stdio.h>

void func() /*Code by me after some tracing */
{
char str[] = " ++c dna c evol I";
int sz = sizeof(str)/sizeof(char);
int i=sz-1;
printf("\n");
switch(8)
{
case 2:while(i)
{
default:printf("%c",str[i--]);}
}
}



使用switch语句可以获得各种乐趣。我承认我经常

很难读取代码来破译它的作用,但是着名的

例子是Duff的设备:http:// en。 wikipedia.org/wiki/Duff''s_device


这段代码看起来像是使用类似的方法向后走过

a字符串来打印_secret_消息。

All sorts of fun can be had with switch statements. I admit I often
have a hard time reading the code to decipher what it does, but a famous
example is Duff''s Device: http://en.wikipedia.org/wiki/Duff''s_device

This code looks like it uses a similar method to walk backwards through
a string to print the _secret_ message.


gopala写道:
gopala wrote:

嘿人,

有人可以解释我怎么样这个片段有效吗?
Hey people,
Can somebody explain me how this fragment works ?



是吗?

Does it?


我遇到了这个问题在

时间,这个比赛真是空白。
I came across
this question in a competition and was really blank about this at the
time.



我希望它丢失,因为,至少,...

I hope it lost, because of, at least, ...


/ *实际代码在竞争中* /
/* Actual code in competition */



[...]

[...]


scanf("%d");
scanf("%d");


5月4日上午8:39,gopala< krishna .... @ gmail.comwrote:
On May 4, 8:39 am, gopala <krishna....@gmail.comwrote:

嘿人们,

有人可以解释一下这个片段是如何工作的吗?我在一场比赛中遇到了这个问题,这个问题在

时间真是空白。

实际上我后来跟踪了这个程序,但是我仍然怀疑为什么编译器似乎忽略了case,default ..。关键字。谢谢

预付款。


#include< stdio.h>


void func()/ *经过一些追踪后我的代码* /

{

char str [] =" ++ c dna c evol I" ;;

int sz = sizeof(str)/ sizeof(char);

int i = sz-1;

printf(" \ n");

开关(8)

{

案例2:while(i)

{

默认值:printf("%c",str [i--]);}

}


}


int main()

{

int i = 0;

/ *竞赛中的实际代码* /

开关(0)

{

案例1:for(; i< 5; i ++)

案例10:{printf("%d",i);

while(i%3!= 0)

案例5:printf(%d,++ i);

默认值:printf(" *");

}}


printf(" \ n\\\
\ n");

func();

scanf("%d" );

返回0;


} - 隐藏引用的文字 -


- 显示引用文字 -
Hey people,
Can somebody explain me how this fragment works ? I came across
this question in a competition and was really blank about this at the
time.
Actually I traced the program later but I still have doubts as to why
the compiler seems to neglect "case, default .. " keywords. Thanks in
advance.

#include <stdio.h>

void func() /*Code by me after some tracing */
{
char str[] = " ++c dna c evol I";
int sz = sizeof(str)/sizeof(char);
int i=sz-1;
printf("\n");
switch(8)
{
case 2:while(i)
{
default:printf("%c",str[i--]);}
}

}

int main()
{
int i=0;
/* Actual code in competition */
switch(0)
{
case 1: for(;i<5;i++)
case 10:{ printf("%d",i);
while(i%3!=0)
case 5: printf("%d",++i);
default: printf("*");
}}

printf("\n\n\n");
func();
scanf("%d");
return 0;

}- Hide quoted text -

- Show quoted text -



请提及比赛中确切要求的内容

Ciao,

AK

Please mention what was exactly asked in the competition

Ciao,
AK


这篇关于转换和朋友的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆