-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12.cpp
41 lines (36 loc) · 993 Bytes
/
12.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <gtest/gtest.h>
#include <map>
#include <string>
using namespace std;
class Solution {
public:
string intToRoman(int num)
{
static const vector<pair<int, string>> roman = {
{1000, "M"}, {900, "CM"}, {500, "D"}, {400, "CD"}, {100, "C"},
{90, "XC"}, {50, "L"}, {40, "XL"}, {10, "X"}, {9, "IX"},
{5, "V"}, {4, "IV"}, {1, "I"}};
string result;
for (const auto &it : roman) {
int value = it.first;
const string &symbol = it.second;
while (num >= value) {
num -= value;
result += symbol;
}
}
return result;
}
};
class Testing : public testing::Test {
public:
Solution s;
};
TEST_F(Testing, Case)
{
EXPECT_EQ(s.intToRoman(3), "III");
EXPECT_EQ(s.intToRoman(4), "IV");
EXPECT_EQ(s.intToRoman(9), "IX");
EXPECT_EQ(s.intToRoman(58), "LVIII");
EXPECT_EQ(s.intToRoman(1994), "MCMXCIV");
}