From 673d75c513b394b16fe75ba9bceda8f5cb4c8022 Mon Sep 17 00:00:00 2001 From: I <1091761+wx257osn2@users.noreply.github.com> Date: Sun, 21 Jun 2020 23:52:53 +0900 Subject: [PATCH 01/19] add compile options --- cpp/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/Makefile b/cpp/Makefile index 0d0081f..8a98ab4 100644 --- a/cpp/Makefile +++ b/cpp/Makefile @@ -4,4 +4,4 @@ clean: rm main main: src/main.cpp - g++ -std=gnu++11 -O3 -o main src/main.cpp + g++ -std=gnu++11 -O3 -Wall -Wextra -march=native -mtune=native -o main src/main.cpp From b400b56dfde9860d5353f2786a2465df0bec2b32 Mon Sep 17 00:00:00 2001 From: I <1091761+wx257osn2@users.noreply.github.com> Date: Sun, 21 Jun 2020 23:53:59 +0900 Subject: [PATCH 02/19] gnu++11 -> c++17 --- README.md | 2 +- cpp/Makefile | 2 +- cpp/src/main.cpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b6b7b20..ab5a795 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ And runs on languages below: - JavaScript : NodeJS 13 - Kotlin : 1.3 + jdk >=8 - Julia : 1.4 -- GCC : 7.5 (or versions which support C++11) +- GCC : 7.5 (or versions which support C++17) I like to use [asdf](https://asdf-vm.com/#/) to set up those environments. diff --git a/cpp/Makefile b/cpp/Makefile index 8a98ab4..791e87f 100644 --- a/cpp/Makefile +++ b/cpp/Makefile @@ -4,4 +4,4 @@ clean: rm main main: src/main.cpp - g++ -std=gnu++11 -O3 -Wall -Wextra -march=native -mtune=native -o main src/main.cpp + g++ -std=c++17 -O3 -Wall -Wextra -pedantic-errors -march=native -mtune=native -o main src/main.cpp diff --git a/cpp/src/main.cpp b/cpp/src/main.cpp index 5278c0d..f4fb06d 100644 --- a/cpp/src/main.cpp +++ b/cpp/src/main.cpp @@ -96,8 +96,8 @@ pair> dijkstra(NodeId start, NodeId end) { NodeIndex e = get_idx(end); int size = g.idx; - Distance d[size] = {}; - NodeIndex prev[size] = {}; + std::vector d(size); + std::vector prev(size); priority_queue, greater> queue; queue.push({0,s}); From 5bf0990f1355eaeb9ff0534e4d03a982be978ae2 Mon Sep 17 00:00:00 2001 From: I <1091761+wx257osn2@users.noreply.github.com> Date: Sun, 21 Jun 2020 23:54:15 +0900 Subject: [PATCH 03/19] unuse bits/stdc++.h --- cpp/src/main.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cpp/src/main.cpp b/cpp/src/main.cpp index f4fb06d..a544949 100644 --- a/cpp/src/main.cpp +++ b/cpp/src/main.cpp @@ -1,4 +1,9 @@ -#include +#include +#include +#include +#include +#include + using namespace std; using NodeId = int; From 3e5dfe941cc1755356583005f1454f79a2b5325c Mon Sep 17 00:00:00 2001 From: I <1091761+wx257osn2@users.noreply.github.com> Date: Mon, 22 Jun 2020 00:07:51 +0900 Subject: [PATCH 04/19] unuse 575 --- cpp/src/main.cpp | 52 +++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/cpp/src/main.cpp b/cpp/src/main.cpp index a544949..f8d5a23 100644 --- a/cpp/src/main.cpp +++ b/cpp/src/main.cpp @@ -4,22 +4,20 @@ #include #include -using namespace std; - using NodeId = int; using NodeIndex = int; using Distance = int; -using Edge = pair; +using Edge = std::pair; const int DISTANCE_MULTIPLE = 100; bool is_debug = false; struct G { - map id2idx; - vector idx2id = {0}; + std::map id2idx; + std::vector idx2id = {0}; NodeIndex idx = 1; - vector> edge = {vector()}; + std::vector> edge = {std::vector()}; } g; NodeIndex get_idx(NodeId id) { @@ -28,7 +26,7 @@ NodeIndex get_idx(NodeId id) { i = g.idx++; g.id2idx[id] = i; g.idx2id.push_back(id); - g.edge.push_back(vector()); + g.edge.push_back(std::vector()); } return i; } @@ -65,12 +63,12 @@ int stof100(const char *s) { } void load() { - string line; - cin >> line; // skip header + std::string line; + std::cin >> line; // skip header while (true) { - cin >> line; - if (cin.eof()) { + std::cin >> line; + if (std::cin.eof()) { break; } int s = 0, e = 0; @@ -87,16 +85,16 @@ void load() { idx++; } } - if (is_debug) cout << "line: " << line << " s: " << s << " e: " << e << " D: " << d << endl; + if (is_debug) std::cout << "line: " << line << " s: " << s << " e: " << e << " D: " << d << std::endl; // cerr << "line:" << line << "s:" << s << " e:" << e << " d:" << d << endl; // std::this_thread::sleep_for(std::chrono::seconds(1)); add_edge(s, e, (int)d); } } -using Visit = pair; +using Visit = std::pair; -pair> dijkstra(NodeId start, NodeId end) { +std::pair> dijkstra(NodeId start, NodeId end) { NodeIndex s = get_idx(start); NodeIndex e = get_idx(end); @@ -104,7 +102,7 @@ pair> dijkstra(NodeId start, NodeId end) { std::vector d(size); std::vector prev(size); - priority_queue, greater> queue; + std::priority_queue, std::greater> queue; queue.push({0,s}); int visited = 0; @@ -113,7 +111,7 @@ pair> dijkstra(NodeId start, NodeId end) { queue.pop(); Distance distance = a.first; NodeIndex here = a.second; - if (is_debug) cout << "visiting: " << here << " distance: " << distance << endl; + if (is_debug) std::cout << "visiting: " << here << " distance: " << distance << std::endl; visited++; for (Edge e : g.edge[here]) { NodeIndex to = e.first; @@ -126,9 +124,9 @@ pair> dijkstra(NodeId start, NodeId end) { } } - cerr << "visited: " << visited << endl; + std::cerr << "visited: " << visited << std::endl; - vector result; + std::vector result; NodeIndex n = e; result.push_back(g.idx2id[n]); @@ -142,25 +140,25 @@ pair> dijkstra(NodeId start, NodeId end) { } int main(int argc, char **argv) { - ios::sync_with_stdio(false); - cin.tie(nullptr); + std::ios::sync_with_stdio(false); + std::cin.tie(nullptr); int count = atoi(argv[1]); - is_debug = argc > 2 && string(argv[2]) == "debug"; + is_debug = argc > 2 && std::string(argv[2]) == "debug"; load(); - cerr << "loaded nodes: " << g.idx << endl; + std::cerr << "loaded nodes: " << g.idx << std::endl; - pair> result; + std::pair> result; for (int i=0; i Date: Mon, 22 Jun 2020 00:46:11 +0900 Subject: [PATCH 05/19] add const --- cpp/src/main.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/cpp/src/main.cpp b/cpp/src/main.cpp index f8d5a23..28c86e8 100644 --- a/cpp/src/main.cpp +++ b/cpp/src/main.cpp @@ -32,8 +32,8 @@ NodeIndex get_idx(NodeId id) { } void add_edge(NodeId start, NodeId end, Distance distance) { - NodeIndex s = get_idx(start); - NodeIndex e = get_idx(end); + const NodeIndex s = get_idx(start); + const NodeIndex e = get_idx(end); g.edge[s].push_back({e, distance}); } @@ -75,7 +75,7 @@ void load() { float d = 0; for (int idx=0, pos=0, prev_pos=0; pos <= line.length(); pos++) { if (line[pos] == ',' || pos == line.length()) { - auto field = line.substr(prev_pos, pos-prev_pos); + const auto field = line.substr(prev_pos, pos-prev_pos); switch (idx) { case 2: s = stoi(field); break; case 3: e = stoi(field); break; @@ -95,10 +95,10 @@ void load() { using Visit = std::pair; std::pair> dijkstra(NodeId start, NodeId end) { - NodeIndex s = get_idx(start); - NodeIndex e = get_idx(end); + const NodeIndex s = get_idx(start); + const NodeIndex e = get_idx(end); - int size = g.idx; + const int size = g.idx; std::vector d(size); std::vector prev(size); @@ -107,15 +107,15 @@ std::pair> dijkstra(NodeId start, NodeId end) { int visited = 0; while (!queue.empty()) { - auto a = queue.top(); + const auto a = queue.top(); queue.pop(); - Distance distance = a.first; - NodeIndex here = a.second; + const Distance distance = a.first; + const NodeIndex here = a.second; if (is_debug) std::cout << "visiting: " << here << " distance: " << distance << std::endl; visited++; - for (Edge e : g.edge[here]) { - NodeIndex to = e.first; - Distance w = distance + e.second; + for (const Edge& e : g.edge[here]) { + const NodeIndex to = e.first; + const Distance w = distance + e.second; if (d[to] == 0 || w < d[to]) { prev[to] = here; d[to] = w; @@ -143,7 +143,7 @@ int main(int argc, char **argv) { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); - int count = atoi(argv[1]); + const int count = atoi(argv[1]); is_debug = argc > 2 && std::string(argv[2]) == "debug"; load(); @@ -151,13 +151,13 @@ int main(int argc, char **argv) { std::pair> result; for (int i=0; i Date: Mon, 22 Jun 2020 01:18:49 +0900 Subject: [PATCH 06/19] suppress warning --- cpp/src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/src/main.cpp b/cpp/src/main.cpp index 28c86e8..c68cff6 100644 --- a/cpp/src/main.cpp +++ b/cpp/src/main.cpp @@ -73,8 +73,8 @@ void load() { } int s = 0, e = 0; float d = 0; - for (int idx=0, pos=0, prev_pos=0; pos <= line.length(); pos++) { - if (line[pos] == ',' || pos == line.length()) { + for (int idx=0, pos=0, prev_pos=0; static_cast(pos) <= line.length(); pos++) { + if (line[pos] == ',' || static_cast(pos) == line.length()) { const auto field = line.substr(prev_pos, pos-prev_pos); switch (idx) { case 2: s = stoi(field); break; From e13d103422966b71757016823e4a0b7e72c05224 Mon Sep 17 00:00:00 2001 From: I <1091761+wx257osn2@users.noreply.github.com> Date: Mon, 22 Jun 2020 01:06:22 +0900 Subject: [PATCH 07/19] change compiler to Clang --- README.md | 2 +- cpp/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ab5a795..162d9c6 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ And runs on languages below: - JavaScript : NodeJS 13 - Kotlin : 1.3 + jdk >=8 - Julia : 1.4 -- GCC : 7.5 (or versions which support C++17) +- Clang : 7 (or versions which support C++17) I like to use [asdf](https://asdf-vm.com/#/) to set up those environments. diff --git a/cpp/Makefile b/cpp/Makefile index 791e87f..6ee8778 100644 --- a/cpp/Makefile +++ b/cpp/Makefile @@ -4,4 +4,4 @@ clean: rm main main: src/main.cpp - g++ -std=c++17 -O3 -Wall -Wextra -pedantic-errors -march=native -mtune=native -o main src/main.cpp + clang++ -std=c++17 -O3 -Wall -Wextra -pedantic-errors -march=native -mtune=native -o main src/main.cpp From 00e6c283decd8d4894cc632ebe94603ee7eee734 Mon Sep 17 00:00:00 2001 From: I <1091761+wx257osn2@users.noreply.github.com> Date: Sun, 21 Jun 2020 23:55:00 +0900 Subject: [PATCH 08/19] use unordered_map --- cpp/src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/src/main.cpp b/cpp/src/main.cpp index c68cff6..c7265c2 100644 --- a/cpp/src/main.cpp +++ b/cpp/src/main.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include @@ -14,7 +14,7 @@ const int DISTANCE_MULTIPLE = 100; bool is_debug = false; struct G { - std::map id2idx; + std::unordered_map id2idx; std::vector idx2id = {0}; NodeIndex idx = 1; std::vector> edge = {std::vector()}; From f03723ff7d630c5ac964402c0bd26c7e8737456c Mon Sep 17 00:00:00 2001 From: I <1091761+wx257osn2@users.noreply.github.com> Date: Mon, 22 Jun 2020 00:08:41 +0900 Subject: [PATCH 09/19] use constexpr --- cpp/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/src/main.cpp b/cpp/src/main.cpp index c7265c2..d689df6 100644 --- a/cpp/src/main.cpp +++ b/cpp/src/main.cpp @@ -9,7 +9,7 @@ using NodeIndex = int; using Distance = int; using Edge = std::pair; -const int DISTANCE_MULTIPLE = 100; +constexpr int DISTANCE_MULTIPLE = 100; bool is_debug = false; From c77460cf9ad570a6dda26a2c5b8599e89b615ef5 Mon Sep 17 00:00:00 2001 From: I <1091761+wx257osn2@users.noreply.github.com> Date: Mon, 22 Jun 2020 00:11:49 +0900 Subject: [PATCH 10/19] use string_view --- cpp/src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cpp/src/main.cpp b/cpp/src/main.cpp index d689df6..a2c7d6a 100644 --- a/cpp/src/main.cpp +++ b/cpp/src/main.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -144,7 +145,7 @@ int main(int argc, char **argv) { std::cin.tie(nullptr); const int count = atoi(argv[1]); - is_debug = argc > 2 && std::string(argv[2]) == "debug"; + is_debug = argc > 2 && std::string_view(argv[2]) == "debug"; load(); std::cerr << "loaded nodes: " << g.idx << std::endl; From 1661dc0cb32d7fa47a0ffac462e717f648aa841f Mon Sep 17 00:00:00 2001 From: I <1091761+wx257osn2@users.noreply.github.com> Date: Mon, 22 Jun 2020 00:14:24 +0900 Subject: [PATCH 11/19] use std::getline for read a line --- cpp/src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/src/main.cpp b/cpp/src/main.cpp index a2c7d6a..438b308 100644 --- a/cpp/src/main.cpp +++ b/cpp/src/main.cpp @@ -65,10 +65,10 @@ int stof100(const char *s) { void load() { std::string line; - std::cin >> line; // skip header + std::getline(std::cin, line); // skip header while (true) { - std::cin >> line; + std::getline(std::cin, line); if (std::cin.eof()) { break; } From d150c0dfb33226afbcabaea4c93b92da350b3cbe Mon Sep 17 00:00:00 2001 From: I <1091761+wx257osn2@users.noreply.github.com> Date: Mon, 22 Jun 2020 00:31:56 +0900 Subject: [PATCH 12/19] improve stof100 --- cpp/src/main.cpp | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/cpp/src/main.cpp b/cpp/src/main.cpp index 438b308..ce36801 100644 --- a/cpp/src/main.cpp +++ b/cpp/src/main.cpp @@ -39,26 +39,25 @@ void add_edge(NodeId start, NodeId end, Distance distance) { } // 123.4567 --> 12345 -int stof100(const char *s) { +int stof100(std::string_view s) { int result = 0; - int place = 0; - for (;*s != '\0'; s++) { - if (*s == '.') { - place = 1; - continue; + int place = 3; + auto it = s.cbegin(); + const auto end = s.cend(); + for(; it != end; ++it) { + if (*it == '.') { + ++it; + break; } result *= 10; - result += *s - '0'; - if (place > 0) { - place++; - if (place >= 3) { - break; - } - } + result += *it - '0'; + } + for(; it != end && place --> 0; ++it) { + result *= 10; + result += *it - '0'; } - while (place < 3) { + while(place --> 0) { result *= 10; - place++; } return result; } @@ -80,7 +79,7 @@ void load() { switch (idx) { case 2: s = stoi(field); break; case 3: e = stoi(field); break; - case 5: d = stof100(field.c_str()); break; + case 5: d = stof100(field); break; } prev_pos = pos+1; idx++; From 41b10e7ff3b06d39bb24bf95c399188193632bd9 Mon Sep 17 00:00:00 2001 From: I <1091761+wx257osn2@users.noreply.github.com> Date: Mon, 22 Jun 2020 00:32:53 +0900 Subject: [PATCH 13/19] implement stoi for string_view --- cpp/src/main.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cpp/src/main.cpp b/cpp/src/main.cpp index ce36801..9515eed 100644 --- a/cpp/src/main.cpp +++ b/cpp/src/main.cpp @@ -38,6 +38,15 @@ void add_edge(NodeId start, NodeId end, Distance distance) { g.edge[s].push_back({e, distance}); } +int stoi(std::string_view s) { + int result = 0; + for(auto&& x : s) { + result *= 10; + result += x - '0'; + } + return result; +} + // 123.4567 --> 12345 int stof100(std::string_view s) { int result = 0; From 1c2521f9d88541764d0ccfcc1344a2bdbb240a73 Mon Sep 17 00:00:00 2001 From: I <1091761+wx257osn2@users.noreply.github.com> Date: Mon, 22 Jun 2020 00:38:25 +0900 Subject: [PATCH 14/19] fix type --- cpp/src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cpp/src/main.cpp b/cpp/src/main.cpp index 9515eed..7aabad6 100644 --- a/cpp/src/main.cpp +++ b/cpp/src/main.cpp @@ -80,8 +80,8 @@ void load() { if (std::cin.eof()) { break; } - int s = 0, e = 0; - float d = 0; + NodeId s = 0, e = 0; + Distance d = 0; for (int idx=0, pos=0, prev_pos=0; static_cast(pos) <= line.length(); pos++) { if (line[pos] == ',' || static_cast(pos) == line.length()) { const auto field = line.substr(prev_pos, pos-prev_pos); @@ -97,7 +97,7 @@ void load() { if (is_debug) std::cout << "line: " << line << " s: " << s << " e: " << e << " D: " << d << std::endl; // cerr << "line:" << line << "s:" << s << " e:" << e << " d:" << d << endl; // std::this_thread::sleep_for(std::chrono::seconds(1)); - add_edge(s, e, (int)d); + add_edge(s, e, d); } } From 8f9e4a1211cee732eeedbe5ecb0e7bbdb7e45470 Mon Sep 17 00:00:00 2001 From: I <1091761+wx257osn2@users.noreply.github.com> Date: Mon, 22 Jun 2020 00:38:39 +0900 Subject: [PATCH 15/19] reduce copy --- cpp/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/src/main.cpp b/cpp/src/main.cpp index 7aabad6..67a444a 100644 --- a/cpp/src/main.cpp +++ b/cpp/src/main.cpp @@ -84,7 +84,7 @@ void load() { Distance d = 0; for (int idx=0, pos=0, prev_pos=0; static_cast(pos) <= line.length(); pos++) { if (line[pos] == ',' || static_cast(pos) == line.length()) { - const auto field = line.substr(prev_pos, pos-prev_pos); + const auto field = std::string_view{line}.substr(prev_pos, pos-prev_pos); switch (idx) { case 2: s = stoi(field); break; case 3: e = stoi(field); break; From 1878ae087351793ffe1e692d67eb7137a9e80175 Mon Sep 17 00:00:00 2001 From: I <1091761+wx257osn2@users.noreply.github.com> Date: Mon, 22 Jun 2020 01:10:00 +0900 Subject: [PATCH 16/19] inline --- cpp/src/main.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cpp/src/main.cpp b/cpp/src/main.cpp index 67a444a..17f3f48 100644 --- a/cpp/src/main.cpp +++ b/cpp/src/main.cpp @@ -21,7 +21,7 @@ struct G { std::vector> edge = {std::vector()}; } g; -NodeIndex get_idx(NodeId id) { +inline NodeIndex get_idx(NodeId id) { NodeIndex i = g.id2idx[id]; if (i == 0) { i = g.idx++; @@ -32,13 +32,13 @@ NodeIndex get_idx(NodeId id) { return i; } -void add_edge(NodeId start, NodeId end, Distance distance) { +inline void add_edge(NodeId start, NodeId end, Distance distance) { const NodeIndex s = get_idx(start); const NodeIndex e = get_idx(end); g.edge[s].push_back({e, distance}); } -int stoi(std::string_view s) { +inline int stoi(std::string_view s) { int result = 0; for(auto&& x : s) { result *= 10; @@ -48,7 +48,7 @@ int stoi(std::string_view s) { } // 123.4567 --> 12345 -int stof100(std::string_view s) { +inline int stof100(std::string_view s) { int result = 0; int place = 3; auto it = s.cbegin(); @@ -103,7 +103,7 @@ void load() { using Visit = std::pair; -std::pair> dijkstra(NodeId start, NodeId end) { +inline std::pair> dijkstra(NodeId start, NodeId end) { const NodeIndex s = get_idx(start); const NodeIndex e = get_idx(end); From 6543a77b8d431eb2d97e25ff4e07db72cb9c8238 Mon Sep 17 00:00:00 2001 From: I <1091761+wx257osn2@users.noreply.github.com> Date: Mon, 22 Jun 2020 01:10:39 +0900 Subject: [PATCH 17/19] use emplace_back --- cpp/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/src/main.cpp b/cpp/src/main.cpp index 17f3f48..b73b8db 100644 --- a/cpp/src/main.cpp +++ b/cpp/src/main.cpp @@ -35,7 +35,7 @@ inline NodeIndex get_idx(NodeId id) { inline void add_edge(NodeId start, NodeId end, Distance distance) { const NodeIndex s = get_idx(start); const NodeIndex e = get_idx(end); - g.edge[s].push_back({e, distance}); + g.edge[s].emplace_back(e, distance); } inline int stoi(std::string_view s) { From 1643babc230bb302bc1fd5def60b27e4dd858fdd Mon Sep 17 00:00:00 2001 From: I <1091761+wx257osn2@users.noreply.github.com> Date: Mon, 22 Jun 2020 16:19:13 +0900 Subject: [PATCH 18/19] stoi -> stoi_unchecked --- cpp/src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cpp/src/main.cpp b/cpp/src/main.cpp index b73b8db..3050062 100644 --- a/cpp/src/main.cpp +++ b/cpp/src/main.cpp @@ -38,7 +38,7 @@ inline void add_edge(NodeId start, NodeId end, Distance distance) { g.edge[s].emplace_back(e, distance); } -inline int stoi(std::string_view s) { +inline int stoi_unchecked(std::string_view s) { int result = 0; for(auto&& x : s) { result *= 10; @@ -86,8 +86,8 @@ void load() { if (line[pos] == ',' || static_cast(pos) == line.length()) { const auto field = std::string_view{line}.substr(prev_pos, pos-prev_pos); switch (idx) { - case 2: s = stoi(field); break; - case 3: e = stoi(field); break; + case 2: s = stoi_unchecked(field); break; + case 3: e = stoi_unchecked(field); break; case 5: d = stof100(field); break; } prev_pos = pos+1; From 8b4338ff53cce85db56aff2ce12ce1e9b62f559c Mon Sep 17 00:00:00 2001 From: I <1091761+wx257osn2@users.noreply.github.com> Date: Mon, 22 Jun 2020 20:45:00 +0900 Subject: [PATCH 19/19] fix type --- cpp/src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/src/main.cpp b/cpp/src/main.cpp index 3050062..bfb5341 100644 --- a/cpp/src/main.cpp +++ b/cpp/src/main.cpp @@ -82,8 +82,8 @@ void load() { } NodeId s = 0, e = 0; Distance d = 0; - for (int idx=0, pos=0, prev_pos=0; static_cast(pos) <= line.length(); pos++) { - if (line[pos] == ',' || static_cast(pos) == line.length()) { + for (std::string::size_type idx=0, pos=0, prev_pos=0; pos <= line.length(); pos++) { + if (line[pos] == ',' || pos == line.length()) { const auto field = std::string_view{line}.substr(prev_pos, pos-prev_pos); switch (idx) { case 2: s = stoi_unchecked(field); break;