首页 >>  正文

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”挑战赛,你会如何作答?

濮刮闻1524c语言简单编程 -
白婷复17839858494 ______ 1.选择排序:sort(int a[10]) { int temp; int i,j; for(i=0;i<9;i++) { for(j=i;j<=9;j++) { if(a[i]<a[j]) { temp=a[i]; a[i]=a[j]; a[j]=temp; } } } }2.也是选择排序:sort(int a[],int n) { int temp; int i,j; for(i=0;i<n-1;i++) { for(j=i;j<=n;j++) { if(a[i]<a[j]) { temp=a[i]; a[i]=a[j]; a[j]=...

濮刮闻1524c语言高手请帮忙,很简单的代码.
白婷复17839858494 ______ #include<stdio.h>main(){ long int i; long b1,b2,b4,b6,b10,b;b1=100000*0.1;b2=b1+100000*0.075;b4=b2+200000*0.05;b6=b4+200000*0.03;b10=b6+400000*0.015;scanf("%ld",&i);if(i<100000)b=i*0.1;if(i<=200000)b=b1+(i-100000)*0.075;if(i<=...

濮刮闻1524一段简单的c语言代码 -
白婷复17839858494 ______ ++,--运算符号出现在变量前面时就必须在表达式计算之前就要加(减);相反,当出现在变量后面时就必须要在表达式计算完毕后再加(减).弄清楚就好了.

濮刮闻1524关于C语言的一段简单的代码 -
白婷复17839858494 ______ 这个问题其实是涉及到getchar()函数的用法.. 执行getchar()输入"一个字符"时,键入字符后需要回车,之后程序才会响应输入,继续执行后面的语句.也会将回车作为一个字符读入..这就相当于一次读取两个字符. 把程序修改下.加个统计次数的输出,你就可以明白了: 在for循环中加个printf("\n%d\n",i);

濮刮闻1524求一个c语言源码,很简单的. -
白婷复17839858494 ______ #include int main() { printf("Hello world!"); return 0; }

濮刮闻1524超简单C语言代码 要问的只有一句! -
白婷复17839858494 ______ i=(j++,++j,j-3); j本来是2,j++后j=3,++4后j=4,所以j-3=1; i=j++; 这个过程可以理解程这样:i=j; j++; 因为i=j++;这句话中,++符号要遇到逗号或者分号的时候,才会回写内存.你这个式子从左向往看,可以看出,先赋值,再遇分号;

濮刮闻1524简单的C语言 -
白婷复17839858494 ______ 两处错误.第一处:scanf("%f%f%f",&a,&b,&c);改为scanf("%lf%lf%lf",&a,&b,&c);或将定义类型double改为float.第二处:你的比较顺序错了!代码如下:#include <stdio.h> int main() { double a,b,c,t; printf("please input 3 numbers\n"); ...

濮刮闻1524关于几个简单的C语言编程 求助大神!! -
白婷复17839858494 ______ Known circle radius, column height, programming for circle circumference, cylinder volume, and accurate to the decimal point 2. 1)程序代码; 1) program code; 2)从键盘上分别输入圆半径、圆柱高为 4、8,输出圆周长、圆柱体积. 2, ...

濮刮闻1524简单c语言 -
白婷复17839858494 ______ #include"stdio.h" int main() { int a,b,c,tmp,max; printf("inputa,b,c:"); scanf("%d%d%d",&a,&b,&c); if(a>b&&a>c) max=a; else if(b>c) max=b; else max=c; printf("max=%d",max); }

濮刮闻1524高分求写几个C语言简单代码作业,今天12点以内. -
白婷复17839858494 ______ 1.#include <stdio.h> int main() { float s,r,t; scanf("%f %f",&s,&r); t=s*r; printf("%0.2f\n",t); return 0; }2.#include <stdio.h>int main(){ zhifloat c; scanf("%f", &c); printf("%.2f\n", c * 1.8 + 32); return 0;}3.#include <stdio.h>#include <math.h>...

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