显性测试数据全对的WA之uva355(已AC)
来源:互联网 发布:河北经济网络电视台 编辑:程序博客网 时间:2024/05/23 01:57
题目:
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)
- WA卡关之uva202(解决问题后已AC)
- 奇葩的uva102(多次WA后已AC)
- Q2007(WA->AC)
- ACM之AC,WA,orPE?
- 为什么?为什么?为什么WA啊!洛谷 [USACO1.1]贪婪的送礼者{已AC}
- 一个G++AC,C++WA的例子(hdu 4107)
- poj 1062 跪求大神帮看,网上大牛的测试数据全过了,然而还是wa。。哭晕
- POJ1661 help Jimmy(动态规划)已ac,附带测试数据
- AC WA or PE
- 显性的调用构造函数(感觉没太大用处)
- (请教)HDOJ2056(WA)(已解决)
- Selenium显性等待的方式
- uva10905同一思路的两种做法,前一种WA,后一种AC
- HDU 5355 Cake (WA后AC代码,详细解析,构造题)
- Uva-202 - Repeating Decimals-WA to AC
- HDOJ2034(为毛别人AC 我WA)
- nyoj1091 (wa 的快进来!!)
- 手机端虚拟键盘弹出使界面布局混乱解决方法
- 自动递增和递减(i++)
- 【JZOJ3297】【SDOI2013】逃考(escape)
- EDA软件_Cadence_OrCAD Capture层次式电路设计
- 字典树的C++实现以及应用
- 显性测试数据全对的WA之uva355(已AC)
- 执行jar包时出现invalid or corrupt jarfile
- bzoj1633
- opencv各种运算
- (转)Android中TextView的SetText()方法注意事项
- 使用Junit进行单元测试时遇到的问题记录[下]
- 采用DIV+CSS模式的网站的优势
- 木马编写小技巧(转)
- [转]JavaScript/Node.JS 中的 Promises