Class Solution {Publicint Romantoint (string s) {int length = S.size ();int result = 0;int pre =getnum (s[0]);for (int i = 1; i{int current = Getnum (S[i]);if (pre*5==current| | Pre*10==current) from left to right, subtract the current value if the current value is smaller than the value on the right, or add the current valueif (preresult = Result-pre;Elseresult = Result+pre;Pre = current;}return result+pre;}int Getnum (char c){//i (1), V (5), X (10), L (50), C (100), D (500), M (1000)if (c== '
#include #include #include intRomantoint (Char* s) {intn=strlen(s);int Map[ -]={0};Map[' I '-' A ']=1;Map[' V '-' A ']=5;Map[' X '-' A ']=Ten;Map[' L '-' A ']= -;Map[' C '-' A ']= -;Map[' D '-' A ']= -;Map[' M '-' A ']= +;intsum=0;intN,nn;intI=0; for(i=0; i//Detect if there is an IV IX XL XC CD CM if(i!=n-1) {n =Map[s[i]-' A ']; nn=Map[s[i+1]-' A '];if(NElsesum + = n; }ElseSum + =Map[s[i]-' A ']; }returnsum;}intMainCharargcChar* * argv) {Char*s ="Cdxcix";//499 intnum = Romantoint (s);p
Given a Roman numeral, convert it to an integer.Input is guaranteed to being within the range from 1 to 3999.Class Solution {public: int Romantoint (string s) { Unordered_mapRoman to Integer
public class Solution {public String inttoroman (int num) {int[] digits = new INT[4]; int i = 0; String s = ""; Digits[i] = num%10; while (num = NUM/10) > 0) {digits[++i] = num%10; } for (int j = 0; J Jan 14-integer to Roman; String; Integer; Math;
Topic Description:Given N and M, the number of the numbers of n can be re-divided by M (the number of leading 0 is forbidden).n (1≤ n ) and m (1≤ m ≤100). Originally intended to do a digital DP and then saw the problem also toward the digital DP on the results ...------------------------------------------------------------------------------------------------------Let's just say the positive solution is a pressure DP.We can use F[I][J] to indicate that the set of numbers used is I, and the num
Question:
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
An1_1:
Class solution {public: String inttoroman (INT num) {// start typing your C/C ++ Solution Below // do not write int main () function string res; string symbol [] = {"M", "cm", "D", "cd", "C", "XC", "L", "XL ", "X", "IX", "V", "IV", "I"}; int value [] = {1000,900,500,400,100, 90, 50, 40, 10, 9, 5 }; int I = 0; while
Question: Ultraviolet A: 185-Roman Numerals
Question: Give a string equality and ask if this string is a Rome equality? Are there any conforming Arabic equations? The former outputs correct or incorrect, and the latter scores:
A combination of letters that can form an Arabic equation must be greater than or equal to 2,There is only one combination of valid letters that can form an Arabic equation.Impossible does not have a combination of letters tha
Design idea: convert input characters into ASCLL code to add and convert to charactersProgram Flowchart:Program Source code:Package Kehouzuoye;import Java.util.scanner;public class Jiami {public static void main (string[] args) {//TODO Auto-gener Ated method Stub Scanner in=new Scanner (system.in); int N=0;int key=3; String m= ""; String Str=new string (); System.out.printf ("Please enter a string to encrypt"); Str=in.next (); for (int j=0;jResults:The ancient
function Dectorom (dec:longint): String;ConstNUMS:ARRAY[1..13] of Integer =(1, 4, 5, 9, 10, 40, 50, 90, 100,400, 500, 900, 1000);ROMANNUMS:ARRAY[1..13] of String =(' I ', ' IV ', ' V ', ' IX ', ' X ', ' XL ',' L ', ' XC ', ' C ', ' CD ', ' D ', ' CM ', ' M ');VarI:integer;BeginResult: = ';For I: = 1 downtowhile (Dec >= nums[i]) doBeginDEC: = Dec-nums[i];Result: = result + Romannums[i];EndEnd
Report:
1, the original link http://dn.codegear.com/es/article/27799
2. Introduction to
Given an integer, convert it to a Roman numeral.Input is guaranteed to being within the range from 1 to 3999.Convert Decimal to Roman numberThe basic symbols of the Roman numerals are I (denoted decimal number 1), V (for 5), X (for Ten), L (denoted by a), C (for the millions), D (for a), M (for 1000). These basic figures, after the compound can represent the othe
Given an integer, convert it to a Roman numeral.Input is guaranteed to being within the range from 1 to 3999.Topic Analysis: Numbers to Roman characters, about the relationship between Roman characters and numbers please refer to the previous Roman character and the number relationshipAlgorithm analysis: There is no us
This article is in the study summary, welcome reprint but please specify Source: http://blog.csdn.net/pistolove/article/details/42744649Given an integer, convert it to a Roman numeral.Input is guaranteed to being within the range from 1 to 3999.Ideas:(1) The test instructions is converted to Roman numerals for a given integer of any 1-3999.(2) This title is similar to converting
Given a Roman numeral, convert it to an integer.Input is guaranteed to being within the range from 1 to 3999.The title means converting a given Roman number to an integer.What are Roman numerals:I, II, III, IV, V, VI, VII, VIII, IX, X .The above Roman numerals are expressed as 1 2 3 4 5 6 7 8 9 10in
A bit of meaning ~ as long as the corresponding treatment for 4 and 9 of the two special cases are good. The rest are simple additions.All right, just stick out my answer, it's ugly ... Not concise enough. Can see the answer of the Hao God ...Python: "" "Programmer:eofdate:2015.04.10file:itr.pye-mail: [emailprotected]" "" "" "varible Description: @ret_string: We put the returning string into this varible @base: Here is the base number F or Roman cou
[LeetCode-interview algorithm classic-Java implementation] [012-Integer to Roman (number to Rome character)], leetcode -- java [012-Integer to Roman )][LeetCode-interview algorithm classic-Java implementation] [directory indexes for all questions]Original question
Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to
#-*-Coding:utf8-*-‘‘‘__author__ = ' [email protected] 'https://oj.leetcode.com/problems/roman-to-integer/Roman to IntegerGiven a Roman numeral, convert it to an integer.Input is guaranteed to being within the range from 1 to 3999.===comments by dabay===First Google a little bit of Roman numerals:I-1V-5X-10L-50C-100D-50
problemGiven a Roman numeral, convert it to an integer.Input is guaranteed to being within the range from 1 to 3999.Tags:math, StringCode Public classSolution { Public intRomantoint (String s) {mapMap=NewHashmapMap. put (' I ',1);Map. put (' V ',5);Map. put (' X ',Ten);Map. put (' L ', -);Map. put (' C ', -);Map. put (' D ', -);Map. put (' M ', +);intresult =0;intLen = S.length (); for(inti =0; I 1; i++) {Charc = S.charat (i);intAdd =Map. get (c);Swit
Source of the topic:https://leetcode.com/problems/integer-to-roman/
Test Instructions Analysis:The problem is to convert the numbers in the interval [1-3999] into Roman numerals.
Topic Ideas:As long as you know how Roman numerals and Arabic numerals are converted, it is not difficult to note that the 900,500,400,90,50,40,9,5,4 should be ' CM ', ' D ',
Problem:Given an integer, convert it to a Roman numeral. Input is guaranteed to being within the range from 1 to 3999.Converts an integer of 1-3999 to Roman numeralsThinking:(1)Contrast exampleSingle Digit Exampleⅰ,1 "ⅱ,2" ⅲ,3 "ⅳ,4" ⅴ,5 "ⅵ,6" ⅶ,7 "ⅷ,8" ⅸ,9 "Example of 10 digitsⅹ,10 "ⅺ,11" ⅻ,12 "xiii,13" xiv,14 "xv,15" xvi,16 "xvii,17" xviii,18 "xix,19" xx,20 "xxi,21" xxii,22 "XXIX,29" XXX,30 "XXXI V,34 "xxx
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.