佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1271|回复: 5

请教教我如何做这题,要用什么code?

[复制链接]
发表于 2-2-2007 12:02 AM | 显示全部楼层 |阅读模式
请问有谁可以给我关于这题的code或告诉我该用什么code?   

Roman numerals are used frequently to indicate dates, in particular the year (for example, MMVI represents the year 2006). There are two main differences between roman and arabic numerals.
  • There is no symbol for zero in roman numerals;
  • Numeral placement in the roman system can indicate either addition or subtraction.
Your task for this lab assignment is to convert a number ranging from 1 to 9999 to its roman numeral equivalent. Roman Numeral ConversionThe conversion is specified using the following cases.
  • I represents 1. Joining two I's together (i.e. II) represents 2, while III represents 3. However, IIII to represent 4 is forbidden because there is a shorter notation.
  • V represents 5. Placing I before V (i.e. IV) will mean subtract I from V, i.e. 4. Note that we do not subtract more than one I from V, so IIV to represent 3 is invalid. Placing I after V (i.e. VI) will mean add I to V, i.e. 6. Likewise, VII and VIII represents 7 and 8. To represent 9 and 10, we do not use VIIII and VV respectively because there exist shorter notations.
  • X represents 10. Following the rule above, IX is 9 while XI is 11.
  • L represents 50 and works in much the same way as V. So XL is 40 while LX is 60. Additionally, XLI is 41, XLV is 45, XLIV is 44, XLVI is 46, XLIX is 49. Hopefully you get the picture...
  • C represents 100.
  • D represents 500.
  • M represents 1000. M is the last character of the roman numeral system so to represent 9000, there is no choice but to use MMMMMMMMM.
The TaskWrite a program roman.java that requests a year from the user. Assuming that the executable is roman, a sample run of the program is shown below. User input is denoted in bold.
Enter the year : 1Year 1 in roman numerals is I.
Enter the year : 2006Year 2006 in roman numerals is MMVI.
Enter the year : 1998Year 1998 in roman numerals is MCMXCVIII.
Enter the year : 9999Year 9999 in roman numerals is MMMMMMMMMCMXCIX.
Enter the year : 9888Year 9888 in roman numerals is MMMMMMMMMDCCCLXXXVIII.


[ 本帖最后由 h@RT3r 于 2-2-2007 12:04 AM 编辑 ]
回复

使用道具 举报


ADVERTISEMENT

发表于 2-2-2007 11:47 AM | 显示全部楼层
任何一种电脑语言都不是问题。

答案的方程式是用最大的值 1000 来除,比如说 2006 / 1000 = 2,就在 string variable 增 2 个 MM,余剩的数目再用比 1000 小的 500 来除,= 0,没有 D,...
回复

使用道具 举报

发表于 2-2-2007 03:58 PM | 显示全部楼层
我用Java寫的架構讓你參考

  1. public Roman(int n) {
  2.     int quotient;
  3.     int mod;
  4.     int i, j;
  5.     final String roman = new String("MDCLXVI");
  6.     final int[] array = {1000, 500, 100, 50, 10, 5, 1};
  7.    
  8.     System.out.print("Year " + n + " in roman numerals is ");
  9.    
  10.     quotient = n / array[0];
  11.     mod = n % array[0];
  12.     for ( i = 0; i < quotient; i++ ) {
  13.         System.out.print(roman.charAt(0));
  14.     }
  15.    
  16.     for ( j = 1; j < roman.length(); j++ ) {
  17.         quotient = mod / array[j];
  18.         mod = mod % array[j];
  19.         // 判斷式自己寫
  20.     }
  21. }
复制代码
回复

使用道具 举报

 楼主| 发表于 3-2-2007 08:16 PM | 显示全部楼层
谢谢你门的帮忙,可以再帮我吗?
这题又如何做?这题是跟上题有关

Write a program clock.java that extends time.java such that the clock will begin ticking from the computed canonical time. The clock face should be updated after every one second has elasped.

Points to Ponder...
As we would like our clock to run for as long as possible, will your program eventually fail to function properly due to overflow error? How would you prevent it from happening? Remember: Overflow prevention is your responsiblity...

How would you expect your clock to perform in the long run? Would it be faster or slower?
回复

使用道具 举报

发表于 3-2-2007 09:01 PM | 显示全部楼层
你到底是不会什么?只贴问题
感觉你是来这里问答案的
回复

使用道具 举报

发表于 15-2-2007 06:49 PM | 显示全部楼层
好像是來騙答案哦﹗﹗﹗
回复

使用道具 举报

Follow Us
您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 13-11-2024 07:15 AM , Processed in 0.104254 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表