111
本帖最后由 胡鸣谦 于 2020-7-17 11:53 编辑#include<iostream>
using namespace std;
int s,maxh,minh;
int main()
{
int n,max,min,mahs,mihs;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>s;
}
max=s;
min=s;
for(int i=1;i<=n;i++)
{
if(s>=max)
{
max=s;
maxh=i;
mahs+=1;
}
if(s<=min)
{
min=s;
maxh=i;
mihs+=1;
}
}
cout<<max<<':';
for(int i=1;i<=mahs;i++)
{
if(maxh!=0)
{
cout<<maxh<<' ';
}
}
cout<<endl;
cout<<min<<':';
for(int i=1;i<=mihs;i++)
{
if(maxh!=0)
{
cout<<minh<<' ';
}
}
return 0;
}
啥吖? 好多处不行 永恒的蓝色梦想 发表于 2020-7-17 11:50
啥吖?
【题目描述】
从键盘输入两行数,第一行n (不大于100)代表数组的个数,第二行连续输入n个数,数之间使用空格隔开,输出最小值和最小值的下标、最大值和最大值的下标,如果存在相同的,则都输出。
【输入输出样例】
输入 输出
10
1 2 3 4 5 6 7 8 9 10 l: 0
10: 9
10
5 4 3 2 1 1 2 3 4 5 1:4 5
5:0 9
乐乐,改成问题求助类型 嘉岳呀 发表于 2020-7-17 12:00
乐乐,改成问题求助类型
改啦 没有
我远程操控一下 帮你改了一下
#include<iostream>
using namespace std;
int s,maxh,minh;
int main()
{
int n,max,min,mahs=0,mihs=0;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>s;
}
max=s;
min=s;
for(int i=0;i<n;i++)
{
if(s>=max)
{
max=s;
}
if(s<=min)
{
min=s;
}
}
for(int i=0;i<n;i++)
{
if(s==max)
{
maxh=i;
mahs+=1;
}
if(s==min)
{
minh=i;
mihs+=1;
}
}
cout<<max<<':';
for(int i=0;i<mahs;i++)
{
cout<<maxh<<' ';
}
cout<<endl;
cout<<min<<':';
for(int i=0;i<mihs;i++)
{
cout<<minh<<' ';
}
return 0;
}
页:
[1]