题目:

Write a program to convert a whole number specified in any base (2..16) to a whole number in any
other base (2..16). “Digits” above 9 are represented by single capital letters; e.g. 10 by A, 15 by F, etc.
Input
Each input line will consist of three values. The first value will be a positive integer indicating the base
of the number. The second value is a positive integer indicating the base we wish to convert to. The
third value is the actual number (in the first base) that we wish to convert. This number will have
letters representing any digits higher than 9 and may contain invalid “digits”. It will not exceed 10
characters. Each of the input values on a single line will be separated by at least one space.
Output
Program output consists of the original number followed by the string ‘base’, followed by the original
base number, followed by the string ‘=’ followed by the converted number followed by the string ‘base’
followed by the new base. If the original number is invalid, output the statement
original_V alue is an illegal base original_Base number
where original_V alue is replaced by the value to be converted and original_Base is replaced by the
original base value.
Sample input
2 10 10101
5 3 126
15 11 A4C
Sample output
10101 base 2 = 21 base 10
126 is an illegal base 5 number
A4C base 15 = 1821 base 11

2017/3/7

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
long long ori(char a[],int k1)
{
    int k,len,i,flag=0;
    long long sum=0;
    for(len=0; a[len]!='\0'; len++);
    for(i=0; i<len; i++)
    {
        if(a[i]==' ')
            k=0;
        else if(a[i]>=65)
            k=a[i]-'A'+10;
        else if(a[i]>=48&&a[i]<=57)
            k=a[i]-'0';
        else k=100;                               //(*******)
        if(k>=k1)
        {
            printf("%s is an illegal base %d number\n",a,k1);
            flag=-1;
            break;
        }

sum=sum*k1+k;
    }
    if(flag!=-1)
        return sum;
    else
        return flag;
}

int change(long long a,char b[],int k)
{
    int c,i1=0,i=0;
    char ch;
    do
    {
        c=a%k;
        if(c>=10)
            b[i1]='A'+c-10;
        else if(c>=0&&c<=9)
            b[i1]='0'+c;
        a=a-c;
        a=a/k;
        i1++;
    }
    while(a!=0);
    b[i1]='\0';
    for(i=0; i<=i1/2-1; i++)
    {
        ch=b[i];
        b[i]=b[i1-i-1];
        b[i1-i-1]=ch;
    }
    return i1;
}

int main()
{
    char a[50];
    int i,kin,kout;
    while ((scanf("%d %d %s",&kin,&kout,a))!=EOF)
    {
        int lenOut;
        long long sum;
        char b[50];
        sum=ori(a,kin);
        if(sum!=-1)
        {
            lenOut=change(sum,b,kout);

printf("%s base %d = %s base %d\n",a,kin,b,kout);
        }

}
    return 0;
}

今日解决问题:1.FFFFFFFFFF会造成40位的2进制,更改了两个数组的大小(从20改为50),将sum均改为了long long

今日发现问题:1.double无法%,无法把long long直接粗暴的换成double

是否AC:否。

考虑问题:是否会输入负数?

-----------------------------------------------------------

3/7.删去此行后AC

分析:原担心有部分奇怪字符输入会可能不是大于而是小于(如askii码为1)

就令k=100,没想到反而出错。

回答问题:是否输入负数:否。

是否AC:是。

显性测试数据全对的WA之uva355(已AC)相关推荐

  1. 重磅!国内最全的3D视觉学习资料已开源

    点击上方"3D视觉工坊",选择"星标" 干货第一时间送达 前言 加入工坊快一年了,这一年里结识了很多优秀的童鞋,他们是一群对技术充满着好奇心的探索者.不知道为什 ...

  2. c 科学计算机 优先级计算,北邮上机复试 科学计算器 —— 由编译器的不同引发的数十次 WA,最后终于AC——总结...

    北邮的上机复试环境用的是标准c/c++,而我从大一开始就用vc6.0,很痛苦的出现了很多不同情况.今天用DEV c++解决了一些问题,总结一下. 1. gets() 和 scanf() gets() ...

  3. 丘成桐全职加入清华,清华已聚齐诺贝尔奖、图灵奖、菲尔兹奖三个“首位华人得主”...

    来源:量子位&AI科技评论 首位菲尔兹奖华人得主丘成桐,受聘清华大学讲席教授! △丘成桐,图源:清华大学官方 这便是清华大学宣布的一则重磅消息. 丘成桐历来有着"数学国王" ...

  4. 对于刷oj时因为scanf()出现wa而cin却AC的详解 【scanf() 和 cin 详解】

    故事还得从昨天讲起,昨天做了一道题及其的诡异,用cin输入AC了.用scanf()却一直的报错或者陷入了 死循环.这让我很费解,我用了fflush(stdin)来排除,发现没有效果.后来我想起之前写过 ...

  5. “虎力全开”采购季,存储产品已就位

    简介:两百多年前,有个叫吴锡麒的少年,在"江南三月听莺天,买酒莫论钱".如今又逢暮春三月,一年一度的开年大促--阿里云上云采购季也拉开了序幕. 两百多年前,有个叫吴锡麒的少年,在& ...

  6. 字节跳动社招全岗位研发面经(已拿offer)

    前言 几经周折,群里小伙伴终于成功进入了字节跳动大厂工作.这套面试经验是他自己和几个小伙伴共同总结的,分享给大家.通过本文,可以帮助大家快速回顾了面试中知识点,其次这套面试手册涵盖了诸多岗位的面试题和 ...

  7. C#版 - Leetcode 201. 数字范围按位与(bitwise AND) - 题解

    C#版 - Leetcode 201. 数字范围按位与(bitwise AND) - 题解 在线提交: https://leetcode.com/problems/bitwise-and-of-num ...

  8. ICCV 2021 Oral | PoinTr:几何敏感的多样点云补全Transformer

    来源丨AI科技评论 作者丨于旭敏.王晔 我们提出了一种几何敏感的点云补全Transformer,通过将点云表示成为一组无序的点代理,并采用Transformer的Encoder-Decoder结构进行 ...

  9. ICCV 2021 Oral | 清华提出PoinTr:几何敏感的点云补全Transformer

    本文转载自:AI科技评论 作者 | 于旭敏    编辑 | 王晔 我们提出了一种几何敏感的点云补全Transformer,通过将点云表示成为一组无序的点代理,并采用Transformer的Encode ...

  10. linux查看全连接队列大小,[TimLinux] TCP全连接队列满

    0. TCP三次握手 syns queue: 半连接队列 accept queue: 全连接队列 控制参数存放在文件:/proc/sys/net/ipv4/tcp_abort_on_overflow中 ...

最新文章

  1. 文章3:车载LIDAR点云数据中杆状地物自动提取与分类
  2. 2017-2018-2 20179204《网络攻防实践》第八周学习总结
  3. 抽象类、抽象方法与代码块
  4. Matlab图片改颜色通道不改名存储
  5. Nginx 作为 WebSockets 代理
  6. KNN实现CIFAR-10数据集识别
  7. 美国发布35页科技趋势报告!
  8. EfficientDet 目标检测开源实现
  9. hello bash
  10. 升级php5.4 mysql5.5_在CentOS上把PHP从5.4升级到5.5
  11. “很多人,到了一定年龄才明白:不要与任何人走的太近”你怎么看?
  12. sql azure 语法_方便SQL笔记本,用于在Azure Data Studio中进行故障排除
  13. Android 中的线程有哪些,原理与各自特点
  14. 客户端软件 大华_大华“飞燕”,一款主打稳定WiFi的路由器!
  15. JAVA时间格式化处理_java时间格式化处理
  16. 易语言大漠多线程模板日志输出
  17. 毕业设计总结篇之终结篇——基于android的创意展示平台(混合app)
  18. 电脑小知识:最常用的10个电脑技巧
  19. 在拍拍二手爱回收出过一次手机后,我才体验到回收二手的快乐
  20. 名帖296 傅山 行书《行书帖选》

热门文章

  1. 图纸上标注的是实际尺寸吗_尺寸数字应该标注图纸上所画实际长度。
  2. 分布式系统 服务 的稳定性
  3. 互联网保险投诉量翻倍 众安与安心财险上榜
  4. el-progress入门学习
  5. 给女朋友讲解什么是代理模式 【java3y将东西太有意思了】
  6. Edison编译时显示No such file or directory
  7. Vim跳转首行与尾行
  8. matlab海底地形数据,海底地形建模器
  9. 英特尔服务器芯片组路线图,英特尔处理器路线图:14nm用到2021年 7nm再等3年
  10. 自己制作一个html网页链接,怎么制作自己的网页链接,学生个人网页制作方法...