📄 好条形图510hist.cpp
字号:
#include<iostream>
#include<fstream>
#include"time.h"
using namespace std;
inline void Swap(int &a,int &b)
{
int temp=a;
a=b;
b=temp;
}
int Patition(int a[],int p,int r)
{
int i=p,
j=r+1;
int x=a[p];
while(true)
{
while(a[++i]<x);
while(a[--j]>x);
if(i>=j)break;
Swap(a[i],a[j]);
}
a[p]=a[j];
a[j]=x;
return j;
}
void QuickSort(int a[],int p,int r)
{
if(p<r)
{
int q=Patition(a,p,r);
QuickSort(a,p,q-1);
QuickSort(a,q+1,r);
}
}
clock_t start,finish;
void main()
{
start=clock();
ifstream in("input.txt");
if(in.fail())
{
cout<<"the input.txt is not exist!";
exit(1);
}
ofstream out("output.txt");
int n;
in>>n;
int *a=new int[n];
int i;
for(i=0;i<n;i++)
in>>a[i];
QuickSort(a,0,n-1);
int count=1;
for(i=0;i<n;i++)
{
if(a[i]==a[i+1])
{
count++;
continue;
}
out<<a[i-count+1]<<" "<<count<<endl;
count=1;
}
delete[]a;
finish=clock();
cout<<finish-start<<endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -