Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1.1 roman: Decoding Roman numerals Write a program s which conta umbers from decima notation into Romas ro tala ng argument, a string containing a

image text in transcribed
image text in transcribed
1.1 roman: Decoding Roman numerals Write a program s which conta umbers from decima notation into Romas ro tala ng argument, a string containing a non-negative integer, and print it Roman numeral equivalent to standard output. Usage roman 3 III $ roman 54 XIV $ roman 1977 Table 1: Numerle value for Roman numerals Symbol Value Symbol Value MOKLIIVIT To o on 4321 COCIIT Roman numerals Roman w ale are written using the symbole I, V, X, L, C, D, and M. The value for the symbols are given in table Often, the value for the Roman numeral can be found by converting each character to its corresponding Integer value and adding up the rewults. For Example MMXX becomes 1000 + 1000 + 10 + 10 = 2020. The exception occurs when C, X, or I appear before a symbol in the next higher row of table In that case, the value of the first symbolis fubtracted from the value of the next symbol. Thus, IV is 4, IX is 9, XL is 40, XC is 90, CD is 400, and CM is 900. Note that we do not use any symbols larger than M, so very large numbers may be written with arbitrarily many M's (eg, 10.000 MMMMMMMMMM). In contrast, the output of roman will include and X at most four times (not more than three consecutively). I at most three time, and D, L, and V each at most once. Thus, your program will write IV and not IIII. Roman numerals do not have a notation for aero, so your program should print nothing if the input is 0. Notes Por roman, it is sufficient to weatoi to convert argv[1] to an int. You will not need to handle any error cu The code to handle hundrede, tens, and one is very similar. Try writing a loop, rather than repeating your prithm three times 1.2 palindrome: String operations I 1.2 palindrome: String operations I Write a program palindrome that tests whether a string is a palindrome, meaning that the sequence of letters is symmetric and is not changed by reversal. palindrome takes a single argument, which is a string containing any combination of upper and lower-case letters, digits, and punctuation marks. palindrome prints "yes" if its string is a palindrome, and "no" otherwise Usage $ ./palindrome Bob yes $ ./palindrome Robert no $ ./palindrome hohoho no $ ./palindrome "Madan, I's Adam." yes $ ./palindrome "A man, a plan, a canal: Panama." yes $ ./palindrome "Two men, two plans, tvo canals: Panamas." no Notes Note that palindromes are Case-insensitive, meaning that "Bob" is a palindrome because "B" and "b" are considered equivalent. Note that the definition of palindrome only considers letters, and ignores all other non-letter characters. Therefore, "Rise to vote, sirl" is a palindrome, because it is equivalent to "risetovotesir which is clearly symmetrie. (The definition of palindrome we are using is unclear regarding digits, so test inputs will not include digit characters.) You are free to implement palindrome in any manner you find convenient. If you are looking for a challenge, implement palindrome such that it allocates no memory, does not modify its argument, and does not examine any character in the argument more than once

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions