-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProject1.cpp
104 lines (97 loc) · 2.36 KB
/
Project1.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <iostream>
#include <fstream>
#include <queue>
#include <string>
using namespace std;
struct Peak
{
Peak()
{
}
Peak(int a, int b)
{
row = a;
column = b;
}
int row;
int column;
};
long points[1001][1001];
int main(int argc, char* argv[])
{
int n, m;
queue<Peak> Peak_List;
ifstream fin;
ofstream fout;
string number = argv[1];
//cout << number << endl;
string Input_name(number + "/matrix.data");
string Output_name(number + "/final.peak");
//cout << Input_name << endl;
fin.open(Input_name);
if(!fin)
{
cout << "Fail to open!";
return -1;
}
else cout << "Open" <<" " << Input_name << " " << "succeed!"<< endl;
fout.open(Output_name);
if(!fout)
{
cout << "Fail to open!";
return -1;
}
else cout << "Open" <<" " << Output_name << " " << "succeed!"<< endl;
fin >> n >> m;
//cout << n <<" " << m << endl;
for(int i = 1; i<=n; i++)
{
for(int j = 1; j<=m; j++)
{
fin >> points[i][j];
//cout << i << " " << j << " " << points[i][j] << endl;
}
}
for(int k = 1; k<=n; k++)
{
for(int l = 1; l<=m; l++)
{
long This = points[k][l];
long Left;
if(l>1)
Left = points[k][l-1];
else
Left = -2147483648;
long Right;
if(l<m)
Right = points[k][l+1];
else
Right = -2147483648;
if(This >= Left && This >= Right)
{
long Up;
if(k>1)
Up = points[k-1][l];
else
Up = -2147483648;
long Down;
if(k<n)
Down = points[k+1][l];
else
Down = -2147483648;
if(This >= Up && This >= Down)
Peak_List.push(Peak(k,l));
}
}
}
//cout << Peak_value << endl;
fout << Peak_List.size() << endl;
//cout << Peak_List.size() << endl;
while(!Peak_List.empty())
{
fout << Peak_List.front().row << " " << Peak_List.front().column << endl;
//cout << Peak_List.front().row << " " << Peak_List.front().column << endl;
Peak_List.pop();
}
return 0;
}