C实现 LeetCode->Integer to Roman
2015-06-11 11:26
302 查看
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
将一个 整形转换为 罗马字符 int范围(1-3999)
Input is guaranteed to be within the range from 1 to 3999.
将一个 整形转换为 罗马字符 int范围(1-3999)
// // IntegerToRoman.c // Algorithms // // Created by TTc on 15/6/11. // Copyright (c) 2015年 TTc. All rights reserved. // #include "IntegerToRoman.h" #include <string.h> #include <stdio.h> #include <stdlib.h> /* 给定一个整数,将其转换成罗马数字。 输入在1到3999的范围内。 从num的高位到低位依次转换。 */ char* intToRoman01(int num) { const char *map[13] = {"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"}; const int value[13] = {1000,900,500,400,100,90,50,40,10,9,5,4,1}; char *result = (char*)malloc(sizeof(char)*100); memset(result,0,100); for (int i = 0; num > 0; i++) { int count = num/value[i]; num %= value[i]; while (count > 0) { strcat(result, map[i]); --count; } } return result; }
相关文章推荐
- hihocoder #1035 : 自驾旅行 III 树形DP
- JAVA 中两种判断输入的是否是数字的方法
- Day12:看节目对于高考的想法
- 利用SQL注入漏洞登录后台
- LeetCode 之 Implement strStr() — C 实现
- 更换Prezi的logo
- 使用AudioTrack进行音频播放
- jQuery Visualize
- dx:trouble processing: bad class file magic (cafebabe) or version (0033.0000)
- Oracle默认密码
- Python标准库13 循环器 (itertools)
- form表单
- Hadoop分布式缓存
- HLJU 1221: 高考签到题 (三分求极值)
- Google C++编程风格
- Debian/Ubuntu默认禁用root帐户的原因
- MyBatis-快速入门
- mark:Eclipse导入workspace存在的项目
- javascript 常见功能汇总
- java工程转web eclipse tomcat下工程不启动