Pagini recente » Cod sursa (job #3256157) | Cod sursa (job #3275380) | Cod sursa (job #2790646) | Cod sursa (job #271113) | Cod sursa (job #3242004)
#include <fstream>
#include <algorithm>
int t[10000000] = {};
int szamlalo = 10;
bool sort(int a, int b){
return a / (szamlalo / 10) % szamlalo < b / (szamlalo / 10) % szamlalo;
}
void radixSort(int t[], int n, int c){
for(int i = 1; i <= c; i++){
std::stable_sort(t, t+n, sort);
szamlalo *= 10;
}
}
int main(){
int n, a, b, c;
std::ifstream bem("radixsort.in");
bem >> n >> a >> b >> c;
bem.close();
t[1] = b;
for(int i = 2; i <= n; i++)
t[i] = (a * t[i-1] + b) % c;
int szJ = 0;
int temp = c;
while(temp > 0){
temp /= 10;
szJ++;
}
radixSort(t, n, szJ);
std::ofstream kim("radixsort.out");
for(int i = 1; i <= n; i += 10)
kim << t[i] << " ";
kim.close();
return 0;
}