一个令人难以置信的C ++问题,至少对我来说! [英] A mind boggling C++ question , atleast to me!

查看:65
本文介绍了一个令人难以置信的C ++问题,至少对我来说!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我的大学里有一个社会负责开发应用程序和类似的东西!所以这是他们在面试中问我的问题,当我申请他们的社会时!



for(等等)

{cout<< ;世界;}



用blah blah短语替换某些内容,将输出打印为: - Hello World!



那一刻我完全糊涂了,我仍然是。有没有办法做到这一点。而且我只被允许改变那个等等的短语,仅此而已。没有代码更改低于或高于该值!

:(

解决方案

你可以用什么来代替等等?

嗯,有三个子句,一个在循环的大部分之前执行,一个测试循环是否应该运行,一个在循环之后执行。



所以如果你要把

 cout<<   Hello 



 cout<<   

在最后,您需要做的就是在之后终止循环第一次迭代...



我会把剩下的留给你 - 这是你的采访!:笑:


我工作过另一个解决方案:



  for (cout<<   Hel世界!;  false ; )
{
cout<< World; (bh blah)
{cout<< 世界; }



替换



blah blah



with



int i = 0; i< 1; i ++)

{

cout< < 你好;

}

for(int i = 0; i< 1; i ++



如果问号确实是真的,然后这个答案是错误的当然



带问号的cout<<世界的世界必须被世界覆盖不知何故,

可能打印Hello World!然后再回到'W'的位置并再次写World,但实际上没有任何改变



  int  i =  0 ; i< 1 ; i ++)
{
cout<< Hello;
}

cout.seekg( 6 ,ios :: begin);

for int i = 0 ; I< 1; i ++在


Ok , There is a society in my college that deals with developing apps and some stuff like that! So here's the question they asked me during the Interview when i applied to their society!

for( blah blah )
{ cout<<"World";}

Replace something with "blah blah" phrase to print the output as :- Hello World !

At that moment i was utterly confused and still i am. Is there any way to do that. And I am only allowed to change the blah blah phrase only , nothing more than that. No code changes below or above that!
:(

解决方案

What can you replace "blah blah" with?
Well, three clauses, one that is executed before the bulk of the loop, one that tests if the loop should run, and one that gets executed after the loop.

So if you were to put

cout << "Hello "

in the first clause, and

cout << " !"

in the last, all you'd need to do is terminate the loop after the first iteration...

I'll leave the rest to you - it's your interview! :laugh:


I worked out another solution:

for(cout<<"Hello World!"; false; )
    {
        cout<<"World";
    }


for( blah blah )
{ cout << "World"; }

replace

blah blah

with

int i=0;i<1;i++ )
{
cout << "Hello ";
}
for ( int i=0;i<1;i++

If the questionmark really is meant to be, then this answer is wrong ofcourse

With questionmark the World from cout << "World" has to be overwritten with "World !" somehow,
maybe print "Hello World !" first then seek back to the pos of 'W' and write World again, but changes nothing in fact

int i=0;i<1;i++ )
{
    cout << "Hello ";
}

cout.seekg( 6, ios::begin );
 
for ( int i=0;i<1;i++


这篇关于一个令人难以置信的C ++问题,至少对我来说!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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