# 根据上排给出十个数，在其下排填出对应的十个数（栈和队列）

0123456789

0

2

0 1 2 3 4 5 6 7 8 9

6 2 1 0 0 0 1 0 0 0

``0 1 2 3 4 5 6 7 8 9``

``6 2 1 0 0 0 1 0 0 0``

``````#include<stdio.h>
#define LEN 10
int arr[LEN] ;//= {0,1,2,3,4,5,6,7,8,9};
int b[LEN] = {};
int get();
int get1(int num);
int main()
{
int k,i,success = 0;
for(i=0;i<10;i++)
scanf("%d",&arr[i]);

while(success == 0)
{
success = get();
}
for(i = 0; i < 9; i++)
{
printf("%d ",b[i]);
}
printf("%d\n",b[i]);
}
int get()
{
int i,num,fre;
int success = 1;
for(i = 0; i < LEN; i++)
{
num = arr[i];
fre = get1(num);
if(b[i] != fre)
{
b[i] = fre;
success = 0;
}
}
return success;
}
int get1(int num)
{
int i;
int count = 0;
for(i = 0; i < LEN; i++)
{
if(b[i] == num)
{
count++;
}
}
return count;
}
``````

``````#include <iostream>
using namespace std;
#define     Maxx 10
class NUM
{
private:
int data[Maxx];
int ans[Maxx];
bool awr;
public:
NUM();
public:
int* input();
void solve();
int di(int value);
};
NUM::NUM()
{
awr = false;
for(int i = 0; i < Maxx; i++)
{
cin>>data[i];
ans[i] =data[i];
}
}
int* NUM::input()
{
int i = 0;
while(!awr)
{
i++;
solve();
}
return ans;
}
void NUM::solve()
{
bool flag = true;
for(int i = 0; i < Maxx; i++)
{
int f = di(data[i]);
if(ans[i] != f)
{
ans[i] = f;
flag = false;
}
}
awr = flag;
}
int NUM::di(int value)
{
int n = 0;
for(int  i = 0; i < Maxx; i++)
{
if(ans[i] == value)
n++;
}
return n;
}
int main()
{
NUM o;
int* ans = o.input();
for(int  i= 0 ; i < Maxx-1; i++)
{
cout << *ans++ <<" ";
}
cout<<*ans<<endl;
return 0;
}
``````