内存不够用,用计数排序可以解决问题。
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<string> #include<cmath> #include<map> #include<set> #include<vector> #include<list> #include<deque> #include<algorithm> #include<stack> #include<queue> #include<cctype> #include<sstream> using namespace std; #define pii pair<int,int> typedef long long int LL; const double eps=1e-10; const int INF=1000000000; const int maxn=600+5; int c[101],n,x; int main() { //freopen("in1.txt","r",stdin); //freopen("out.txt","w",stdout); while(scanf("%d",&n)==1&&n) { memset(c,0,sizeof(c)); for(int i=0; i<n; i++) { scanf("%d",&x); c[x]++; } int first=1; for(int i=1; i<=100; i++) { //cout<<"c"<<i<<‘:‘<<c[i]<<endl; if(c[i]>0) { while(c[i]--) { if(first==1) { first=0; printf("%d",i); } else { printf(" %d",i); } } } } printf("\n"); } return 0; }
时间: 2024-10-23 02:20:20