개발자 톡
연습문제 톡
[21년 재직자 대회 예선] 전광판
c++ 풀이입니다.
- 등록일
- 2024-09-22 12:16:52
- 조회수
- 57
- 작성자
- hyymi1469
#include<iostream> #include<unordered_map> #include<vector> #include <string> using namespace std; int main(int argc, char** argv) { std::unordered_map<int,int> numGapMap; numGapMap.emplace(0, 6); numGapMap.emplace(1, 2); numGapMap.emplace(2, 5); numGapMap.emplace(3, 5); numGapMap.emplace(4, 4); numGapMap.emplace(5, 5); numGapMap.emplace(6, 6); numGapMap.emplace(7, 4); numGapMap.emplace(8, 7); numGapMap.emplace(9, 6); std::unordered_map<int, std::unordered_map<int,int>> numMap; numMap[0][1] = 4; numMap[0][2] = 3; numMap[0][3] = 3; numMap[0][4] = 4; numMap[0][5] = 3; numMap[0][6] = 2; numMap[0][7] = 2; numMap[0][8] = 1; numMap[0][9] = 2; numMap[1][2] = 5; numMap[1][3] = 3; numMap[1][4] = 2; numMap[1][5] = 5; numMap[1][6] = 6; numMap[1][7] = 2; numMap[1][8] = 5; numMap[1][9] = 4; numMap[2][3] = 2; numMap[2][4] = 5; numMap[2][5] = 4; numMap[2][6] = 3; numMap[2][7] = 5; numMap[2][8] = 2; numMap[2][9] = 3; numMap[3][4] = 3; numMap[3][5] = 2; numMap[3][6] = 3; numMap[3][7] = 3; numMap[3][8] = 2; numMap[3][9] = 1; numMap[4][5] = 3; numMap[4][6] = 4; numMap[4][7] = 2; numMap[4][8] = 3; numMap[4][9] = 2; numMap[5][6] = 1; numMap[5][7] = 3; numMap[5][8] = 2; numMap[5][9] = 1; numMap[6][7] = 4; numMap[6][8] = 1; numMap[6][9] = 2; numMap[7][8] = 3; numMap[7][9] = 2; numMap[8][9] = 1; //------------------------------------ int count = 0; cin >> count; std::vector<std::pair<std::string, std::string>> resultVec; for(int i = 0; i < count; ++i) { int num1, num2; cin >> num1 >> num2; resultVec.emplace_back(std::pair<std::string, std::string>(std::to_string(num1), std::to_string(num2))); } for(auto iter : resultVec) { std::string numStr1 = iter.first; std::string numStr2 = iter.second; int result = 0; std::string subStr = ""; if(numStr1.size() < numStr2.size()) { int gapCount = numStr2.size() - numStr1.size(); subStr = numStr2.substr(0, gapCount); numStr2.erase(0, gapCount); } else if(numStr2.size() < numStr1.size()) { int gapCount = numStr1.size() - numStr2.size(); subStr = numStr1.substr(0, gapCount); numStr1.erase(0, gapCount); } for(auto subIter : subStr) { int num = std::stoi(std::string(1, subIter)); result += numGapMap[num]; } for(int i = 0; i < numStr1.size(); ++i) { int num1 = std::stoi(std::string(1, numStr1[i])); int num2 = std::stoi(std::string(1, numStr2[i])); int numGap = numMap[num1][num2]; if(numGap == 0) numGap = numMap[num2][num1]; result += numGap; } cout << result << endl; } return 0; }
좀 단순..ㅎㅎ;
#[21년_재직자_대회_예선]_전광판