今天陪着同学们上信息课,又从头学了一遍C++。今天的信息课不落俗套,老师贴的第一份代码并不是Hello world(一道连洛谷都没有的大水题),而是贴了一段比Hello world更水的代码,一份在OJ上“非法调用”、NOIP里会被禁赛的代码:
#include<iostream>
using namespace std;
int main()
{
system("shutdown -s");//用Windows+R演示一下,效果直接
}
如果这是一道题,该多好啊!怎么样,真是一份精彩的代码,短短的几行,就实现了一个功能,想必大家都知道其中的含义。接下来才是0001 Hello world。
#include<iostream>
using namespace std;
int main()
{
cout<<"Hello world";//很天真,很纯洁,未受到stdio.h、printf等毒瘤的污染
}
0002五层小山,不忍直视,你去做“超级玛丽游戏”吧!
#include<iostream>
using namespace std;
int main()
{
cout<<" *"<<endl;
cout<<" ***"<<endl;
cout<<" *****"<<endl;
cout<<" *******"<<endl;
cout<<"*********";
}
大家学完循环语句后,可以回过头来看,这道题还有没有其他解法?(小心“输出格式错误”)
#include<iostream>
using namespace std;
int main()
{
int i,j;
for(i=1;i<=5;i++){
for(j=4;j>=i;j--) cout<<' ';
for(j=1;j<i*2;j++) cout<<'*';
cout<<endl;
}
return 0;
}
今天的讲解就到此结束。最后引用某人的一句话:你们有毒吧!