In this problem you are asked to write a simplebase conversion program. You will be givena hexadecimal or decimal integer number as input.You will have to output the correspondingdecimal or hexadecimal number. Hexadecimalnumbers always starts with a ‘0x’ and all othernumbers are to be considered as decimal numbers.There will be no invalid numbers in theinput.

Input

The input file contains several lines of input. Each line contains a single non-negative number, whichmay be a decimal or hexadecimal number as explained in the problem statement. The decimal value ofthis number will be less than 231. A line containing a negative decimal number terminates input. Thisnumber should not be processed. Input numbers will contain no space within them.

Output

For each line of input (Except the last one) produce one line of output. This line should contain thedecimal or hexadecimal representation of the corresponding hexadecimal or decimal number. Like theinput, the hexadecimal numbers in the output should be preceded by a ‘0x’.

Sample Input

4

7

44

0x80685

-1

Sample Output

0x4

0x7

0x2C

525957

问题链接:UVA10473 Simple Base Conversion

问题简述:(略)

问题分析

  这是一个进制转换问题,要充分利用格式化输入输出函数和字符串与整数之间转换的函数。

  充分利用这些函数,程序逻辑就简单了。

程序说明:(略)

题记:(略)

参考链接:(略)

AC的C语言程序如下:

/* UVA10473 Simple Base Conversion */#include <stdio.h>
#include <stdlib.h>#define N 16
char s[N];int main(void)
{while (gets(s) != NULL && s[0] != '-')if(s[1] == 'x')printf("%ld\n", strtol(s, NULL, 16));elseprintf("0x%X\n", atoi(s));return 0;
}

UVA10473 Simple Base Conversion【进制转换】相关推荐

  1. 探索C/C++ 进制转换之美:从原理到应用

    一.简介 (Introduction) 进制 前缀表示 整数常量示例 转换库接口 参数及返回值示例 二进制 0b 或 0B 0b1010 std::bitset<> std::bitset ...

  2. POJ - 1220 NUMBER BASE CONVERSION(高精度运算+进制转换+模拟)

    题目链接:点击查看 题目大意:给出两个进制x和y,再给出一个x进制下的数num,求num转换为y进制后的答案 题目分析:直接套模板就行了,进制转换没什么好说的,直接模拟,这个题开了加速外挂只能优化几十 ...

  3. 数据结构——进制转换(10—n)

    进制转换(10进制--n进制) 所需知识:栈 #include<stdio.h> #include<bits/stdc++.h> using namespace std; #i ...

  4. python十进制转八进制_Python 内置函数进制转换的用法(十进制转二进制、八进制、十六进制)...

    使用Python内置函数:bin().oct().int().hex()可实现进制转换. 先看Python官方文档中对这几个内置函数的描述: bin(x) Convert an integer num ...

  5. c语言进制转换实验报告,c语言_各种进制转换.docx

    c语言_各种进制转换.docx c 语言 各种进制转换 计算机中常用的数的进制主要有二进制.八进制.十六进制. 2 进制,用两个阿拉伯数字0.1: 8 进制,用八个阿拉伯数字0.1.2.3.4.5.6 ...

  6. python内置函数bin,Python内置函数bin() oct()等实现进制转换

    Python内置函数bin() oct()等实现进制转换 使用Python内置函数:bin().oct().int().hex()可实现进制转换. 先看Python官方文档中对这几个内置函数的描述: ...

  7. python 自定义进制转换,Python 内置函数进制转换的用法(十进制转二进制、八进制、十六进制)...

    使用Python内置函数:bin().oct().int().hex()可实现进制转换. 先看Python官方文档中对这几个内置函数的描述: bin(x) Convert an integer num ...

  8. 单片机进制转换实现(报告+源码)

    用4x4矩阵及LCD1602液晶显示实现各进制转换 摘要:在计算机及其相关的各领域中,数制的二进制.八进制.十进制和十六进制之间的相互转换可谓无处不在.为满足相关领域人员对进制转换计算的需求,特此利用 ...

  9. 进制转换converse

    栈和队列是在软件设计中常用的两种数据结构,它们的逻辑结构和线性表相同. 其特点在于运算受到了限制:栈按"后进先出"的规则进行操作,队按"先进先出"的规则进行操作 ...

最新文章

  1. 表达式必须是可修改的左值怎么解决_如何解决代码腐败的味道
  2. UITableView 局部刷新
  3. MyBatis-04 MyBatis XML方式之insert元素
  4. 文献记录(part32)--Face spoofing detection under super-realistic 3D wax face attacks
  5. sed以及awk的替换命令
  6. 经济学与计算机学收入,考研心得,计算机专业跨考经济学复习经验谈
  7. 稀疏矩阵的压缩存储--十字链表(转载)
  8. 刷爆AI圈!基于Transformer的DALL-E代码刚刚开源了
  9. CI框架解决jsonp跨域的问题
  10. python怎么添加ui_大神可以帮我看看怎么把这个python代码利用ui运行呢
  11. spyder怎么执行html文件,spyder添加快捷键
  12. html语言hr标记,HTML水平线段HR标记详解
  13. 英特尔Skylake处理器全面入驻Google Compute Engine
  14. 多边形对角线交点个数
  15. Ubuntu 22.04 安装中文输入法
  16. C#调用sql存储过程
  17. H - 图书管理系统
  18. java mail 抄送多用户,JavaMail 发送邮件,收件人为多人,抄送多人。其中包含收件人邮箱错误时的处理...
  19. P72:子类和父类的关系
  20. 适合教孩子编码的 7 款免费编程语言

热门文章

  1. 记一次PHP服务器500错误的解决方法
  2. 7个现象告诉你手游圈为什么会有寒冬
  3. 关于用C#编写ActiveX控件1
  4. VueRouter基础知识记录1
  5. 企业微信应用设置可信域名_怎么设置企业微信朋友圈功能?企业微信朋友圈功能有哪些限制?...
  6. php按条件修改xml,php 修改、增加xml结点属性的实现代码
  7. 计算机多媒体技术视差估计,立体视觉中视差估计算法研究
  8. 如何打开电脑就自动显示html文件,电脑教程:Win10怎么打开html文件
  9. Collection 属性ArrayList.add方法内部调用过程
  10. 每天Leetcode 刷题 初级算法篇-缺失数字