From 70090a66e7d96cabd32e504dfdb4af9dd12e47d9 Mon Sep 17 00:00:00 2001 From: user Date: Wed, 29 Jul 2026 20:15:10 +0400 Subject: [PATCH] refactor: remove unnecessary using declarations and qualify std symbols Replace global using declarations with explicit std:: qualifications. Update ranges algorithms usage to std::ranges and fix permutation iterator offset to correctly handle 1-based k indexing. --- 3518/solution.cpp | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/3518/solution.cpp b/3518/solution.cpp index efb16eb..45fbf10 100644 --- a/3518/solution.cpp +++ b/3518/solution.cpp @@ -4,25 +4,19 @@ #include #include -using std::set; -using std::string; -using std::ranges::next_permutation; -using std::ranges::reverse; -using std::ranges::sort; - class Solution { public: - string smallestPalindrome(string s, int k) { + std::string smallestPalindrome(std::string s, int k) { - string half = s.substr(0, s.size() / 2); + std::string half = s.substr(0, s.size() / 2); - sort(half); + std::ranges::sort(half); - set permutations; + std::set permutations; do { permutations.insert(half); - } while (next_permutation(half).found); + } while (std::ranges::next_permutation(half).found); if (permutations.size() > std::numeric_limits::max()) { throw std::overflow_error("Number of permutations exceeds int limit"); @@ -30,14 +24,14 @@ public: int size = static_cast(permutations.size()); if (k > size) { - return string(); + return std::string(); } auto it = permutations.begin(); advance(it, k - 1); - string mirroredHalf = *it; - reverse(mirroredHalf); + std::string mirroredHalf = *it; + std::ranges::reverse(mirroredHalf); return *it + mirroredHalf; }