#include <iostream.h>
#include<fstream.h>
#include<stdlib.h>
void main()
{
int *src; //指向源数组首元素的指针变量
int *dst; //指向结果数组首元素的指针变量
int j,Count;//Count为数组元素的个数
ifstream cin("input.txt");
cin>>Count;
src=new int[Count];//动态分配数组空间
dst=new int[Count];
for(int i=0;i<Count;i++)
cin>>src[i]; //输入数组元素
for(i = 0; i<Count-1; i++)
{
j=i+1; //和下一个元素比较
while(src[i]>src[j] && j<Count) //找到一个比当前大的。
j++;
if(j==Count) //到结尾了,没有大的
dst[i]=-1;
else
dst[i]=j;
}
dst[Count-1]=-1;
ofstream outf("output.txt");
for(i=0; i<Count; i++)
{
cout<<dst[i]<<" ";
outf<<dst[i]<<" ";
}
delete [] src;//释放申请的空间
delete [] dst;
}
评论0