Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2234795

Browse files
author
zhunago
committed
触宝
1 parent bad6013 commit 2234795

File tree

2 files changed

+180
-0
lines changed

2 files changed

+180
-0
lines changed

‎nowcoder/大水.cpp‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <algorithm>
4+
5+
using namespace std;
6+
7+
void dfs(vector<vector<bool>> &visi, vector<vector<int>> &land, int i, int j, int h)
8+
{
9+
if(i < 0 || i >= land.size() || j < 0 || j >= land[0].size() || visi[i][j] || land[i][j] > h)
10+
{
11+
return;
12+
}
13+
visi[i][j] = true;
14+
dfs(visi, land, i + 1, j, h);
15+
dfs(visi, land, i - 1, j, h);
16+
dfs(visi, land, i, j + 1, h);
17+
dfs(visi, land, i, j - 1, h);
18+
}
19+
20+
int main(void)
21+
{
22+
int m, n, h;
23+
cin >> m >> n >> h;
24+
vector<vector<int>> land(m, vector<int>(n, 0));
25+
vector<vector<bool>> visi(m, vector<bool>(n, false));
26+
for(int i = 0; i < m; ++i)
27+
{
28+
for(int j = 0; j < n; ++j)
29+
{
30+
cin >> land[i][j];
31+
}
32+
}
33+
for(int i = 0; i < m; ++i)
34+
{
35+
if(!visi[i][0] && land[i][0] <= h)
36+
{
37+
dfs(visi, land, i, 0, h);
38+
}
39+
if(!visi[i][n - 1] && land[i][n -1] <= h)
40+
{
41+
dfs(visi, land, i, n-1, h);
42+
}
43+
}
44+
45+
for(int i = 0; i < n; ++i)
46+
{
47+
if(!visi[0][i] && land[0][i] <= h)
48+
{
49+
dfs(visi, land, 0, i, h);
50+
}
51+
if(!visi[m - 1][i] && land[m - 1][i] <= h)
52+
{
53+
dfs(visi, land, m - 1, i, h);
54+
}
55+
}
56+
int count = 0;
57+
for(int i = 0; i < m; ++i)
58+
{
59+
for(int j = 0; j < n; ++j)
60+
{
61+
if(!visi[i][j]) count += 1;
62+
}
63+
}
64+
cout << count << endl;
65+
66+
return 0;
67+
}

‎nowcoder/表达式.cpp‎

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <algorithm>
4+
#include <string>
5+
#include <stack>
6+
7+
using namespace std;
8+
9+
int getnextNumber(string &s, int &index)
10+
{
11+
int num = 0;
12+
while (index < s.size() && s[index] >= '0' && s[index] <= '9')
13+
{
14+
num *= 10;
15+
num += s[index] - '0';
16+
index += 1;
17+
}
18+
return num;
19+
}
20+
int main(void)
21+
{
22+
string s;
23+
cin >> s;
24+
int index = 0;
25+
stack<int> st;
26+
stack<char> op;
27+
if(s[0] == '-')
28+
{
29+
index += 1;
30+
int num = getnextNumber(s, index);
31+
st.push(-num);
32+
}
33+
else if(s[0] == '+')
34+
{
35+
index += 1;
36+
int num = getnextNumber(s, index);
37+
st.push(num);
38+
}
39+
char oo = 'n';
40+
while (index < s.size())
41+
{
42+
int oldindex = index;
43+
int num = getnextNumber(s, index);
44+
if (oldindex != index)
45+
{
46+
oo = 'n';
47+
st.push(num);
48+
continue;
49+
}
50+
if (s[index] == '-')
51+
{
52+
index++;
53+
int temp = getnextNumber(s, index);
54+
55+
if(oo == '*' || oo == '/') num = 0;
56+
else
57+
{
58+
num = st.top();
59+
st.pop();
60+
}
61+
num = num - temp;
62+
st.push(num);
63+
oo = '-';
64+
}
65+
else if (s[index] == '+')
66+
{
67+
index++;
68+
int temp = getnextNumber(s, index);
69+
if(oo == '*' || oo == '/') num = 0;
70+
else
71+
{
72+
num = st.top();
73+
st.pop();
74+
}
75+
num = num + temp;
76+
st.push(num);
77+
oo = '+';
78+
}
79+
else
80+
{
81+
oo = s[index];
82+
op.push(s[index]);
83+
index += 1;
84+
}
85+
86+
}
87+
while (!op.empty())
88+
{
89+
char o = op.top();
90+
op.pop();
91+
if (o == '*')
92+
{
93+
int a = st.top();
94+
st.pop();
95+
int b = st.top();
96+
st.pop();
97+
a = b * a;
98+
st.push(a);
99+
}
100+
else if (o == '/')
101+
{
102+
int a = st.top();
103+
st.pop();
104+
int b = st.top();
105+
st.pop();
106+
a = b / a;
107+
st.push(a);
108+
}
109+
}
110+
cout << st.top() << endl;
111+
112+
return 0;
113+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /