Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <deque>
- #include <string>
- int main() {
- std::deque<int> arab;
- std::cout << "Please enter a roman numeral in All-Caps..." << std::endl;
- std::string roman;
- std::getline(std::cin, roman);
- for (unsigned int i = 0; i < roman.size(); i++) {
- int temp;
- switch (roman[i]) {
- case 'I':
- temp = 1;
- break;
- case 'V':
- temp = 5;
- break;
- case 'X':
- temp = 10;
- break;
- case 'L':
- temp = 50;
- break;
- case 'C':
- temp = 100;
- break;
- case 'D':
- temp = 500;
- break;
- case 'M':
- temp = 1000;
- break;
- }
- arab.emplace_back(temp);
- }
- int result = 0;
- while(arab.size() > 0){
- int temp = 0;
- if (arab.size() == 1) {
- result += arab[0];
- arab.pop_front();
- break;
- }
- if (arab[0] >= arab[1]) {
- result += arab[0];
- arab.pop_front();
- }
- else {
- result -= arab[0];
- arab.pop_front();
- }
- }
- std::cout << "Result: " << result << std::endl;
- std::getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement