Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integer to Roman #35

Closed
Tracked by #100
fkdl0048 opened this issue Sep 28, 2024 · 0 comments
Closed
Tracked by #100

Integer to Roman #35

fkdl0048 opened this issue Sep 28, 2024 · 0 comments
Assignees
Labels
Milestone

Comments

@fkdl0048
Copy link
Owner

fkdl0048 commented Sep 28, 2024

#include <vector>
#include <string>

using namespace std;

class Solution {
public:
    string intToRoman(int num) {
        vector<int> n = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
        vector<string> s = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
        
        string str;
        int i = 0;
        
        while(num > 0){
            if (num >= n[i]) {
                str += s[i];
                num -= n[i];
            } 
            else {
                i++;
            }
        }
        
        return str;
    }
};
  • 문자열과 대응되는 값이 있어야 한다면 미리 매칭하기
@fkdl0048 fkdl0048 mentioned this issue Sep 28, 2024
7 tasks
@fkdl0048 fkdl0048 self-assigned this Sep 28, 2024
@fkdl0048 fkdl0048 added this to Todo Sep 28, 2024
@github-project-automation github-project-automation bot moved this to Todo in Todo Sep 28, 2024
@fkdl0048 fkdl0048 moved this from Todo to In Progress in Todo Sep 28, 2024
@fkdl0048 fkdl0048 added this to the LeetCode milestone Sep 28, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Done in Todo Sep 29, 2024
@fkdl0048 fkdl0048 mentioned this issue Oct 15, 2024
47 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

No branches or pull requests

1 participant