Today is a day to remember;
Xun Yu finished all the questions on the first page of oj;
Question 99 made Xun Yu deeply impressed. Although it was not completed independently (with reference to Lian Haoming's code), it is still necessary to integrate it;
Old rules, put the topic first:
Topic description
When programming using the discretization method, it is usually necessary to know the sorted number (rank value) of each number. The same number corresponds to a number.
rank[i] represents the rank of the i-th number among all numbers.
input format
Line 1: An integer N in the range [1...100000]. Line 2: There are N integers, each of which is in the int range. Note: There may be the same integer.
output format
Output the rank of each number in turn.
sample data
input
5
8 2 6 9 2
output
3 1 2 4 1
Data size and convention
Guarantee 1<=N<=100000 Each number does not exceed 1000000
time limit:1s1s
Space Constraints:256MB256MB
Okay, now let's talk about Xun Yu's ideas:
After all, it is an array sorting problem, so put the array in first;
So Xun Yu, who wanted to use a function, used a void-type function called cina, which means inserting the a array;
Then sort and arrange it, and use a very watery void function called paixu, which has only one line of code for the sort function;
Next, mark the sorted array;
final output;
put code:
#include<bits/stdc++.h>
using namespace std;
int n,a[1000100]={},b[1000100]={},c[1000100]={},d=1;
void cina()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
b[i]=a[i];
}
}
void paixu()
{
sort(a+1,a+n+1);
}
void biaoji()
{
for(int i=1;i<=n-1;i++)
if(a[i+1]!=a[i])
{
c[a[i]]=d;
d++;
}
c[a[n]]=d;
}
void couta()
{
for(int i=1;i<=n-1;i++)
cout<<c[b[i]]<<' ';
cout<<c[b[n]];
}
int main()
{
cina();
paixu();
biaoji();
couta();
return 0;
}
using namespace std;
int n,a[1000100]={},b[1000100]={},c[1000100]={},d=1;
void cina()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
b[i]=a[i];
}
}
void paixu()
{
sort(a+1,a+n+1);
}
void biaoji()
{
for(int i=1;i<=n-1;i++)
if(a[i+1]!=a[i])
{
c[a[i]]=d;
d++;
}
c[a[n]]=d;
}
void couta()
{
for(int i=1;i<=n-1;i++)
cout<<c[b[i]]<<' ';
cout<<c[b[n]];
}
int main()
{
cina();
paixu();
biaoji();
couta();
return 0;
}
Today, I finally decided to try the informatics competition. I will spend less water and more questions in the future;
End of full text.