首页 >>  正文

c语言有趣的代码

来源:baiyundou.net   日期:2024-07-09

整理 | 于轩

出品 | 程序人生(ID:coder_life)

近日,国外代码编写平台Intervee上创建了一个简单的编程挑战(挑战链接:https ://platform.intervee.io/get/play_/ch/hello_[w09]orld),要求解答者print "Hello World",但是代码不能使用字母W或者任何数字。

虽然该挑战面向的是初级开发人员,但是仍有很多2年以上工作经验的开发人员参与并公开了解决方案。(173位用户尝试解题,共有148位在没收到虚拟面试官提示的情况下,在推荐时间内挑战成功了。)

其中,只有30%的解答者是初级(0-2年经验)开发人员,同时85%未按时解决问题的解答者也是初级开发人员。这也意味着这项挑战对新手来说很难,听起来也是检查候选人是初级还是高级的好方法。

最后,平台挑选了几个有趣的结果分享了出来,下面一起来看看吧!

最常见和最简单的:使用 %c 说明符

提醒:ascii中的char 87是W

printf("Hello %corld", ++*(char[]){"V"});

printf("Hello %corld", *"V" | *"A");

printf("Hello %corld", *"*" + *"-");

char c = c^c++;

c=(c

printf("Hello %corld", EUSERS);

EUSERS 确实是 87:

https://kernel.googlesource.com/pub/scm/linux/kernel/git/nico/archive/+/v0.97/include/linux/errno.h

这个解决方案需要添加一个特定的#include,所以可能不是最短的代码。

酷酷的C++解决方案

char c = (sizeof(bool)+sizeof(short)) * (sizeof(long) * sizeof(float) - sizeof(char) - sizeof(short));cout << "Hello " << c << "orld";

值得一提的是,解决方案被保存为多个步骤,因此可以看到解答者是如何进行的,而不仅仅是他的最终解决方案。比如说(来自:https://platform.intervee.io/)

超酷的Python解决方案

from googletrans import Translatortext = 'Hola Mundo!'translator = Translator()print(translator.translate(text).text)

import hello# _hellol is a known library that prints hello world. Problem solved.

C 和 C++ 中的“加密”方法

char str[] = "Obkkh'Phukc\\n";char strPtr = str; while (strPtr != '\\n') *strPtr++ ^= '\\a';printf("%s", str);

同样的方法,在 C++ 中

std::string str = "V_xyz";char v_x;for(auto i:str){ v_x=i; break; }v_x++;std::cout<

酷炫的作弊方案

system("echo \\"echo Hello World\\" > /usr/bin/gcc");

解答者发现挑战使用 /usr/bin/gcc处的gcc来编译代码,于是将其替换为“echo Hello World”,超级好!

最后,你还有其他独特的解决方案吗?欢迎参与挑战!

原文链接:

https://www.intervee.io/2022/07/21/10-ways-to-write-hello-world-in-c/

","force_purephv":"0","gnid":"94d540a870e1f0d55","img_data":[{"flag":2,"img":[{"desc":"","height":"80","s_url":"https://p0.ssl.img.360kuai.com/t0186957a1ca5352752_1.gif","title":"","url":"https://p0.ssl.img.360kuai.com/t0186957a1ca5352752.gif","width":"640"},{"desc":"","height":"310","title":"","url":"https://p0.ssl.img.360kuai.com/t014ea6a03905330d65.jpg","width":"627"},{"desc":"","height":"510","title":"","url":"https://p0.ssl.img.360kuai.com/t01d117100d58ebba2d.jpg","width":"566"}]}],"original":0,"pat":"art_src_1,fts0,sts0","powerby":"hbase","pub_time":1660615087000,"pure":"","rawurl":"http://zm.news.so.com/a645c111d0dc0bbe1fe40231f9796e1a","redirect":0,"rptid":"611a75f336cd9f67","s":"t","src":"CSDN","tag":[],"title":"C语言编写“Hello World”挑战赛,你会如何作答?

冀览天3589趣味C语言小编程 -
冉宏才13728594646 ______ 题眼就是求出2~10的最小公倍数,然后减一. 模拟排队的算法是可行的,但不是最优的.#include <stdio.h> int od(int x,int n) //x是否能被n整除,是返回1,否返回0 { if (x%n) return 0; return 1; } int gbs(int a[],int n) //求a[n]内所有元素的最小公倍数 ...

冀览天3589求一些用C语言编写的有趣程序 -
冉宏才13728594646 ______ 用vc就可以,它是专门做工程的,兼容C语言和C++,TC2.0是C语言的集成编译环境软件

冀览天3589用c语言可以写什么有趣的东西. -
冉宏才13728594646 ______ C语言可以做的东西其实是很多的,但是国内大学教材一般都是只简单介绍了C的语法规则之类的.用C可以搞嵌入式开发,系统开发,游戏开发…….

冀览天3589C语言有趣的printf -
冉宏才13728594646 ______ printf()也是一个函数,而且它需要的第一个参数是个字符指针,也就是说,printf()函数的的第一个参数可以是个字符指针,而不一定非要是一个字符串常量.知道这一点后就可以理解这个调用了:它等价于:char *p=(x%2)?("**%d"):("##%d\n"); printf(p,x); 明白了吗,如果不明白,那么进一步等价于(虽然语法上可能不怎么正确,但是这里要说明的是它的算法):char *p; if (x%2!=0) p="**%d"; else p="##%d\n"; printf(p,x);

冀览天3589搞怪C语言小程序 -
冉宏才13728594646 ______ // 这个好办.VC里新建一个win32工程,把这段代码贴到WinMain所在的cpp //然后在资源视图里按照我发的图添加控件.主要是 //那个文本框的id要设置为IDC_INPUT //把原先的OK按钮的文字改成“确定” #include "stdafx.h" #include "...

冀览天3589求助啊,谁有有趣的c语言小程序,并且要有源代码!! -
冉宏才13728594646 ______ #include #include #define numOfQuestions 10 void main() { srand(1); for(int i=0;i a)b = rand()%100; } printf("%d %c %d =?", a, oper, b); int answer = 0; scanf("%d", &answer); bool correct = false; if(add) { if(answer == (a + b)) correct = true; } ...

冀览天3589麻烦帮忙用C语言写一个猜单词游戏的代码.(最好有注解) -
冉宏才13728594646 ______ #inclode void main;{printf("please lend me some money\n");}

冀览天3589用C语言写个代码,利用空格和符号拼写出生日快乐之类的 -
冉宏才13728594646 ______ #include <stdio.h> #include <math.h> float f(float x, float y, float z) { float a = x * x + 9.0f / 4.0f * y * y + z * z - 1; return a * a * a - x * x * z * z * z - 9.0f / 80.0f * y * y * z * z * z;}float h(float x, float z) { for (float y = 1.0f; y >= 0.0f; y -= 0.001f) if (f(x, y, z) <= 0.0f) ...

冀览天3589学完了C语言能做什么有趣的程序(有趣的)??? -
冉宏才13728594646 ______ 如果跟硬件,如单片机(单片机比较简单)结合,可以做一些控制,甚至是智能机器人. 如果不跟硬件结合,可以做游戏,比较有意思,还有其他的方面我就不是很了解了

冀览天3589求助啊,谁有有趣的c语言小程序,并且要有源代码!!
冉宏才13728594646 ______ #include <stdlib.h>#include <stdio.h> #include <math.h>#include <time.h>#define numOfQuestions 10void main(){ srand(1); for(int i=0;i<numOfQuestions ;i++){ bool add = rand()%2; char oper = '-'; if(add) oper = '+'; int a = rand()%100; int b = rand()...

(编辑:自媒体)
关于我们 | 客户服务 | 服务条款 | 联系我们 | 免责声明 | 网站地图 @ 白云都 2024