首页 >>  正文

c语言字母一行八个输出

来源:baiyundou.net   日期:2024-08-28

整理 | 于轩

出品 | 程序人生(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":"cache","pub_time":1660615087000,"pure":"","rawurl":"http://zm.news.so.com/a645c111d0dc0bbe1fe40231f9796e1a","redirect":0,"rptid":"611a75f336cd9f67","s":"t","src":"CSDN","tag":[],"title":"C语言编写“Hello World”挑战赛,你会如何作答?

阚顺阀1883c语言编程,键盘输入一行字符,统计其中字母,空格,数字和其他字符的个数,并输出 -
谈胖露17698106603 ______ #include int main() { int numCnt=0,charCnt=0,spaceCnt=0,albCnt=0; char c; while ((c=getchar()) != '\n') { if (c = '0') numCnt++; else if (c ='a') albCnt++; else if (c ='A') albCnt++; else if (c == ' ') spaceCnt++; else charCnt++; } printf("%d, %d, %d, %d other", numCnt, albCnt, spaceCnt, numCnt); return 0; }

阚顺阀1883C语言 输入一行字符,分别统计求出其中英文字母、空格、数字和其他字符的个数并输出结果 -
谈胖露17698106603 ______ ||#include "stdio.h" void main() { char s; int i=0,j=0,k=0,m=0,da=0,xiao=0; printf("please input the string\n"); while((s=getchar())!='\n') /*循环从键盘读入字符直到一行结束(输入回车)*/ { if((s='a')||(s'A')) { if(s='A')da++; if(s='a')xiao++; i++; ...

阚顺阀1883c语言输入一行字符,输出其中英文字符、空格、数字和其他字符的个数.帮忙找找问题. #include -
谈胖露17698106603 ______ #include int main() { int letter,number,space,other; int ch; letter=number=space=other=0; while ((ch=getchar())!='\n') { if('A'<=ch&&ch<='Z'||'a'<=ch&&ch<='z') letter++; else if(ch==' ') space++; else if('0'<=ch&&ch<='9') number++; else ...

阚顺阀1883C语言:让用 户输入 一个坐标值 (一共是8行8列),输出如下: 请高手修改代码,谢谢了 -
谈胖露17698106603 ______ #include #define LSIZE4 2 int main (void) { int option,c,r; int flag=0; char a='+'; char b='.'; int i=-5,j; char input[LSIZE4]; char row[LSIZE4]; char column[LSIZE4]; printf ("please input 1 for rood or 2 for bishop: "); fgets(input,LSIZE4,stdin); option = atoi...

阚顺阀1883C语言 程序 字符输出 -
谈胖露17698106603 ______ %3s是只有3个空格,在这里明显有7个字母,所以程序自动忽视,%3S无效%8.3s是有八个空格,取前三个字母右对齐.%0.4S中是有0个空格,程序自动忽视,去前四个字母%-8.3S是有八个空格,取前三个字母左对齐

阚顺阀1883怎么样C语言随即输出指定的几个英语字母 -
谈胖露17698106603 ______ 代码如下: #include<iostream> #include<string.h> using namespace std; int main() { freopen("output.txt","w",stdout); string s; cin>>s; for(int i=0;i<500;i++) { cout<<s<<" "<<s<<" "<<s<<" "<<s<<endl; } return 0; }

阚顺阀1883用c语言从键盘输入一串字符字母,按从小到大的顺序输出 -
谈胖露17698106603 ______ 一个排序就搞定了啊!如果不想自己写排序,可以用qsort.1234567891011121314151617181920 #include <stdio.h>#include <stdlib.h>#include <string.h>#define LINELEN 1024 intcmp(constvoid*p1, constvoid*p2) { return*((char*)p1) - *((char*)...

阚顺阀1883C语言输出大小写字母,数字,及其他字符个数,怎么写?急急急!!!! -
谈胖露17698106603 ______ #include #define n 20 //你可以改变n的值,但要保证n至少大于你想输入的字符数目一位 void main() { int i,bc,lc,m; //bc为大写的字母,lc为小写的字母 char a[n]; i=bc=lc=m=0; printf("输入字符串,以#号结束:\t"); gets(a); while(a[i]!='\0') { if(a[i]>='a'&&a[i]='a'&&a[i]

阚顺阀1883C语言句子字母排序后行输出 -
谈胖露17698106603 ______ #include <iostream> using namespace std; void main() { char ch[100]; cin.getline(ch,100); cout<<ch<<endl; int dex=0; while (ch[dex]!='\0') { if ((ch[dex]>'Z'||ch[dex]<'A')&&(ch[dex]>'z'||ch[dex]<'a')&&ch[dex]!=' ') { cout<<"ERROR at: "<<ch+dex<<endl...

阚顺阀1883编写C语言程序,输出所有大写英文字母及对应的ASCII码,代码分别用八进制、十进制和十六进制形式输出. -
谈胖露17698106603 ______ #include <stdio.h> int main(){ for(char a='A';a<='Z';a ){ printf("%c:\n",a); printf("八进制:%o\n",a); printf("十进制:%d\n",a); printf("十六进制:%x\n",a); } return 0; } 如果不放心的话,可以把输出语句里的a都换成(int)a

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