今天,
玉树临风文武双全全面发展鹤立鸡群技高一筹维度宇宙银河系太阳系地球超级无敌帅的作者发现,不用while、for循环也能解决循环问题!
看一下这道题:
比大小
题目描述
输入若干个数(以零结尾),输出这若干个数的最大值。
输入
输入若干个数(以零结尾)。
输出
该数组的最大值
样例输入
15
64
81
12
7
150
0
样例输出
150
题目来源
打擂台思想
新学的小白,是不是会这么做:
#include<bits/stdc++.h>
using namespace std;
int main(){
int x;
int max=INT_MIN; //将最小值装进max变量,这样任何一个数都比max大
while(1){
cin>>x;
if(x>max){
max=x;
}
else{
if(x==0){
break;
}
}
}
cout<<max;
return 0;
}
或者这样:
#include<bits/stdc++.h>
using namespace std;
int main(){
int x;
int max=INT_MIN;
for(;;){
cin>>x;
if(x>max){
max=x;
}
else{
if(x==0){
break;
}
}
}
cout<<max;
return 0;
}
但经过作者的10000个世纪左右的研究,发现这样也行:
#include<bits/stdc++.h>
using namespace std;
int main(){
int x,max=INT_MIN;
p:
cin>>x;
if(x>max) max=x;
else if(x==0){
cout<<max;
return 0;
}
goto p;
}
是不是轻松多了,行数也少多了。
当然,一些爱装B的猿们,可以用最上面的两种办法,装作自己代码打的多。
好了,作者大大要去写稿了,BYEBYE~
啊,又水了一期文章,接下来水什么好呢?
有了,写坑人代码吧!
焯,忘记关闭了,被你们看见了!!!!!!!!!!不~~~~~