i0Ek3 1 year ago
parent
commit
a1547ce07b
3 changed files with 115 additions and 0 deletions
  1. 50
    0
      wd/oth/application-map.cpp
  2. 37
    0
      wd/oth/application-string.cpp
  3. 28
    0
      wd/oth/rolling-array.cpp

+ 50
- 0
wd/oth/application-map.cpp View File

@@ -0,0 +1,50 @@
1
+#include <cstdio>
2
+#include <map>
3
+#include <string>
4
+using std::map;
5
+using std::string;
6
+#define N 100
7
+
8
+map<string, int> M;
9
+int inDegree[2000];
10
+
11
+int main()
12
+{
13
+        int n;
14
+        while (scanf("%d", &n) != EOF && n != 0) {
15
+                for (int i = 0; i < 2*n; i++) {
16
+                        inDegree[i] = 0;
17
+                }
18
+                M.clear();
19
+                int idx = 0;
20
+                for (int i = 0; i < n; i++) {
21
+                        char s1[N], s2[N];
22
+                        scanf("%s%s", s1, s2);
23
+                        string a = s1, b = s2;
24
+                        int idxa, idxb;
25
+                        if (M.find(a) == M.end()) {
26
+                                idxa = idx;
27
+                                M[a] = idx++;
28
+                        } else {
29
+                                idxa = M[a];
30
+                        }
31
+                        if (M.find(b) == M.end()) {
32
+                                idxb = idx;
33
+                                M[b] = idx++;
34
+                        } else {
35
+                                idxb = M[b];
36
+                        }
37
+                        inDegree[idxb]++;
38
+                }
39
+                int ans = 0;
40
+                for (int i = 0; i < idx; i++) {
41
+                        if (inDegree[i] == 0) {
42
+                                ans++;
43
+                        }
44
+                }
45
+                puts(ans == 1 ? "Yes" : "No");
46
+        }
47
+        
48
+        return 0;
49
+}
50
+

+ 37
- 0
wd/oth/application-string.cpp View File

@@ -0,0 +1,37 @@
1
+#include <cstdio>
2
+#include <iostream>
3
+#include <string>
4
+#include <algorithm>
5
+#include <ctype.h>
6
+#define N 100
7
+
8
+int main()
9
+{
10
+        char str[N];
11
+        gets(str);
12
+        std::string a = str;
13
+        for (int i = 0; i < a.size(); i++) {
14
+                a[i] = tolower(a[i]);
15
+        }
16
+        while (gets(str)) {
17
+                std::string b = str, c = b; 
18
+                for (int i = 0; i < b.size(); i++) {
19
+                        b[i] = tolower(b[i]);
20
+                }
21
+                int tmp = b.find(a, 0);
22
+                while (tmp != std::string::npos) {
23
+                        c.erase(tmp, a.size());
24
+                        b.erase(tmp, a.size());
25
+                        tmp = b.find(a, tmp);
26
+                }
27
+                tmp = c.find(' ', 0);
28
+                while (tmp != std::string::npos) {
29
+                        c.erase(tmp, 1);
30
+                        tmp = c.find(' ', 0);
31
+                }
32
+                std::cout << c << std::endl;
33
+        }
34
+        
35
+        return 0;
36
+}
37
+

+ 28
- 0
wd/oth/rolling-array.cpp View File

@@ -0,0 +1,28 @@
1
+
2
+void state1() {
3
+        for (int i = 1; i <= n; i++) {
4
+                for (int j = 1; j <= m; j++) {
5
+                        dp[i][j] = max(dp[i-1][j+1], dp[i-1][j-1]);
6
+                }
7
+        }
8
+        int ans = dp[n][m];
9
+}
10
+
11
+
12
+
13
+int state2() {
14
+        int *src;
15
+        int *des;
16
+        int n, m;
17
+        while (scanf("%d%d", &n, &m) != EOF) {
18
+                for (int i = 1; i <= n; i++) {
19
+                        std::swap(src, des);
20
+                        for (int j = 1; j <= m; j++) {
21
+                                des[j] = std::max(src[j+1], src[j-1]);
22
+                        }
23
+                }
24
+                int ans = des[m];
25
+        }
26
+}
27
+
28
+

Loading…
Cancel
Save