# Turbo Sort Problem

Hello, I don’t know why my code doesn’t get AC, can you help me?
Here’s my code:

``````#include <bits/stdc++.h>
using namespace std;

void fastscan(int &number) {
bool negative = false;
register int c;
number = 0;
c = getchar();
if (c=='-') {
negative = true;
c = getchar();
}

for (; (c>47 && c<58); c=getchar())
number = number *10 + c - 48;

if (negative)
number *= -1;
}

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);

int t;
fastscan(t);

if (t < 1){
return 0;
}

vector<vector<int>> numbers;
for (int i = 0; i < 10; i++){
vector <int> numberVector;
numbers.insert(numbers.end(), numberVector);
}

for(int i = 0; i < t; i++){
int integer;
fastscan(integer);
if (integer == 0){
numbers[0].insert(numbers[0].end(), integer);
continue;
}
numbers[integer].insert(numbers[integer].end(), integer);
}

for(int i = 0; i <= 9; i++){
for(int x = 0; x < numbers[i].size(); x++){
cout << numbers[i][x] << "\n";
}
}

return 0;
}``````

The variable “Integer” in your code can be up to 10^6
you can literally just do this in c++

``````#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >>t;
vector<int> seq(t);
for(auto &x : seq){
cin>>x;
}
sort(seq.begin(), seq.end());
for(const auto &x : seq){
cout<<x<<"\n";
}
}
``````

Alternatively, If you want to go with your approach, you can do this

``````#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int MAXN=1000000;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >>t;
vector<vector<int>> seq(MAXN, vector<int>());
for(int i=0;i<t;i++){
int x;
cin>>x;
seq[x].push_back(x);
}
for(const auto &val : seq){
for(const auto &x : val){
cout<<x<<"\n";
}
}
}
``````
1 Like