-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBai46_DichTrai.cpp
More file actions
59 lines (44 loc) · 915 Bytes
/
Bai46_DichTrai.cpp
File metadata and controls
59 lines (44 loc) · 915 Bytes
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
#include <iostream>
#include<fstream>
using namespace std;
void readFile(const char* fileName, size_t &n, int* arr,size_t &d) {
fstream ifs(fileName);
if (ifs.fail()) {
cout << "Loi";
}
ifs >> n;
for (int i = 0; i < n; i++) {
ifs >> arr[i];
}
ifs >> d;
ifs.close();
}
void ouputFile(const char* fileName, int n, int* arr) {
ofstream ofs(fileName);
for (int i = 0; i < n; i++) {
ofs << arr[i]<<" ";
}
ofs.close();
}
void dichTrai(int n, int* arr,int d) {
int temp = arr[0];
int j = 0;
while (true) {
int k = j + d;
if (k >= n)
k -= n;
if (k == 0)
break;
arr[j] = arr[k];
j = k;
}
arr[j] = temp;
}
int main()
{
size_t n,d;
int* arr = new int[100];
readFile("C:\\Users\\ASUS\\Desktop\\CodePTIT\\41..50\\Bai46_DichTrai\\Data.txt",n,arr,d);
dichTrai(n, arr, d);
ouputFile("C:\\Users\\ASUS\\Desktop\\CodePTIT\\41..50\\Bai46_DichTrai\\Result.txt", n, arr);
}