• Sign Up
• Login
• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Apr 25th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. //README : e o metoda foarte idioata de sortare dar nu imi iese
2. // pt input : 6 4 1 7 5 1 3
3. // alege ca minim 1 (de pe poz 5/6 ) de fiecare data
4.
5. #include <fstream>
6.
7. using namespace std;
8.
9. ifstream in("algsort.in");
10. ofstream out("algsort.out");
11.
12.
13. int n;
14. int arr[10000];
15. int sorted[10000];
16. int counter = 1;
17.
18. void read()
19. {
20.     in >> n;
21.     for (int i = 1; i <= n; i++) in >> arr[i];
22. }
23.
24.
25. void sortit()
26. {
27.     int min = arr[1];
28.     int max = 0;
29.     int mins = 0;
30.
31.     for (int i = 1; i <= n; i++) //fac maximul
32.     {
33.         if (arr[i] >= max) max = arr[i];
34.     }
35.
36.     for (int i = 1; i <= n; i++)
37.     {
38.         for (int i = 1; i <= n; i++) //fac minimul
39.         {
40.             if (arr[i] <= min) min = arr[i];
41.             mins = i;
42.         }
43.         sorted[counter] = min; // adaug minimul in vectorul sortat
44.         arr[mins] = max; // pun un maxim in vectorul initial ca sa nu mai iau acelasi minim inca o data
45.         counter++; //cresc indicele pt vecotrul de sortati
46.         mins = 0;
47.     }
48. }
49.
50. void outit()
51. {
52.     for (int i = 1; i <= n; i++) out << sorted[i] << ' ';
53. }
54.
55.
56.
57. int main()
58. {
59.     read();
60.     sortit();
61.     outit();
62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top