现在的位置: 首页 > 综合 > 正文

对数组A中的N(0<N<100)个…

2014年03月19日 ⁄ 综合 ⁄ 共 741字 ⁄ 字号 评论关闭

 

对数组A中的N(0
      
A=(5,3,4,7,3,5,6)    
则输出应为:(3,1,2,5,1,3,4)
即数组A中整数5依从小到大的序号为3,整数3依从小到大的序号为1,…

//

#include "stdafx.h"
#include
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
 int a[100],i=0,Na=0;//i记录a数组元素个数
 cout<<"输入一组数,用空格隔开,用回车结束"<<endl;

 do
 {
  cin>>a[i++];
 }while(getchar()!='\n');
 Na=i;//Na记录了a数组的实际元素个数
 int b[100],j=0,Nb=0;//Nb记录了b数组的实际元素个数
 //将a数组中不重复的数据输入b数组
 for(i=0;i
 {
  for(j=0;j
  {
   if(a[i]==b[j])

    break;

  }
  if(j==Nb)
  {
   b[j]=a[i];

   Nb++;
  }
 }

 ////直接插入法排序数组b:
 int temp=0;
 for(i=1;i
 {
  temp=b[i];
  j=i-1;
  while(j>=0&&temp

  {
   b[j+1]=b[j];

   j--;
  }
  b[j+1]=temp;
 }

 //输出a数组的编号
 cout<<"a数组的编号"<<endl;
 for(i=0;i
 {
  j=0;
  while(a[i]!=b[j++]);//a[i]和b数组中数据逐个比较

  cout<<j<<" ";
 }
 system("pause");//这行可以不要

}

欢迎访问我的网站船长旅游网。有很齐全的旅游攻略,景点介绍,旅游博客

抱歉!评论已关闭.