-
Notifications
You must be signed in to change notification settings - Fork 0
/
5-2.cpp
69 lines (66 loc) · 1.17 KB
/
5-2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include<iostream>
using namespace std;
#include <iostream>
using namespace std;
template<typename T>
void Input(T *a,int len)
{
for (int i = 0; i < len; i++)
{
cin >> a[i];
}
}
template<typename T>
void Sort(T* a, int len)
{
for (int i = 0; i < len-1; i++)
{
for (int j = i+1; j < len; j++)
{
if (a[i] > a[j])
{
T temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
}
template<typename T>
void Output(T* a, int len)
{
for (int i = 0; i < len; i++)
{
cout << a[i] << " ";
}
}
int main()
{
const int LEN = 5;
int type;
while (std::cin >> type)
{
switch (type)
{
case 0:
{
int a1[LEN];
Input(a1, LEN); Sort(a1, LEN); Output(a1, LEN);
break;
}
case 1:
{
char a2[LEN];
Input(a2, LEN); Sort(a2, LEN); Output(a2, LEN);
break;
}
case 2:
{
double a3[LEN];
Input(a3, LEN); Sort(a3, LEN); Output(a3, LEN);
break;
}
}
}
return 0;
}