nyoj1277 Decimal integer conversion (河南省acm第九届省赛)

本文主要是介绍nyoj1277 Decimal integer conversion (河南省acm第九届省赛),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Decimal integer conversion

时间限制: 1000 ms  |  内存限制: 65535 KB
难度: 2
描述
XiaoMing likes mathematics, and he is just learning how to convert numbers between different bases , but he keeps making errors since he is only 6 years old. Whenever XiaoMing converts a number to a new base and writes down the result, he always writes one of the digits wrong. For example , if he converts the number 14 into binary (i.e., base 2), the correct result should be "1110", but he might instead write down "0110" or "1111". XiaoMing never accidentally adds or deletes digits, so he might write down a number with a leading digit of " 0" if this is the digit she gets wrong. Given XiaoMing 's output when converting a number N into base 2 and base 3, please determine the correct original value of N (in base 10). (N<=10^10) You can assume N is at most 1 billion, and that there is a unique solution for N. 
输入
The first line of the input contains one integers T, which is the nember of test cases (1<=T<=8)
Each test case specifies:
* Line 1: The base-2 representation of N , with one digit written incorrectly.
* Line 2: The base-3 representation of N , with one digit written incorrectly.
输出
For each test case generate a single line containing a single integer , the correct value of N
样例输入
1
1010
212
样例输出
14
来源
河南省第九届省赛
上传者
onlinejudge

题意就是小明将一个十进制的数转化为2进制或者三进制的时候总会错一个数字  求这个十进制数。暴力即可

水题一枚

 
#include <stdio.h>
#include <string.h>
#include <math.h>
char a[105];
char b[105];
long long getnum(char *c,int x,int len)
{long long res=0;for(int i=0;i<len;i++){res+=(c[i]-'0')*pow(x,len-i-1);}return res;
}
int main()
{int t;scanf("%d",&t);while(t--){memset(a,0,sizeof(a));memset(b,0,sizeof(b));scanf("%s",a);scanf("%s",b);int len1=strlen(a);int len2=strlen(b);char ch1,ch2;long long num1,num2;int find=-1;for(int i=0;i<len1;i++){ch1=a[i];if(a[i]=='0') a[i]='1';else a[i]='0';num1=getnum(a,2,len1);//	printf("num1=%d\n",num1);for(int j=0;j<len2;j++){ch2=b[j];b[j]='0';if(ch2!=b[j]){num2=getnum(b,3,len2);if(num1==num2){find=num1;break;}}if(find!=-1) break;b[j]='1';if(ch2!=b[j]){num2=getnum(b,3,len2);if(num1==num2){find=num1;break;}}if(find!=-1) break;b[j]='2';if(ch2!=b[j]){num2=getnum(b,3,len2);if(num1==num2){find=num1;break;}}b[j]=ch2;}if(find!=-1){break;}a[i]=ch1;}printf("%d\n",find);}
}        


这篇关于nyoj1277 Decimal integer conversion (河南省acm第九届省赛)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/694632

相关文章

C#中,decimal类型使用

在Microsoft SQL Server中numeric类型,在C#中使用的时候,需要用decimal类型与其对应,不能使用int等类型。 SQL:numeric C#:decimal

泛型和Integer小结

泛型在Java.util里面找:也可对其他你使用的函数进行查阅 如下:只要函数后面跟有尖括号<>,你都可以拿过来使用泛型     注意:用到集合时尽量使用泛型       int与Integer   integer这个不是关键字,是java的一个类。也就是int的包装类。int是基本数据类型,integer是引用类型,包含很多属性和方法,而int只是一个值,没有其他的任何

【会议征稿,ACM出版】2024年图像处理、智能控制与计算机工程国际学术会议(IPICE 2024,8月9-11)

2024年图像处理、智能控制与计算机工程国际学术会议(IPICE 2024)将于2024年8月9-11日在中国福州举行。本届会议由阳光学院、福建省空间信息感知与智能处理重点实验室、空间数据挖掘与应用福建省高校工程研究中心联合主办。 会议主要围绕图像处理、智能控制与计算机工程等研究领域展开,旨在为从事计算机等相关研究的专家学者提供一个交流科研成果和前沿技术的平台,了解学术发展趋势,拓宽研究思路

杭电ACM hdu 2110 Crisis of HDU 解题报告(母函数)

Problem Description 话说上回讲到HDU大战东洋小苟,结果自然是中方大胜,这一战也使得海东集团在全球同行业中的地位更加巩固。随着集团的发展,很多创业时期的元老逐步功成身退,先是8600移民海外,然后是linle夫妇退隐山林,逐渐的,最初众多的元老只剩下XHD夫妇和Wiskey三人了。 到了2020年,因为扩张过度加上老鼠数量逐年减少,公司的发展遇到了前所未有的危机,此时集团已经

杭电ACM hdu 2082 找单词 解题报告(母函数)

Problem Description 假设有x1个字母A, x2个字母B,..... x26个字母Z,同时假设字母A的价值为1,字母B的价值为2,..... 字母Z的价值为26。那么,对于给定的字母,可以找到多少价值<=50的单词呢?单词的价值就是组成一个单词的所有字母的价值之和,比如,单词ACM的价值是1+3+14=18,单词HDU的价值是8+4+21=33。(组成的单词与排列顺序无关,比如

杭电ACM hdu 2079 选课时间 解题报告(母函数)

Problem Description 又到了选课的时间了,xhd看着选课表发呆,为了想让下一学期好过点,他想知道学n个学分共有多少组合。你来帮帮他吧。(xhd认为一样学分的课没区别)   Input 输入数据的第一行是一个数据T,表示有T组数据。 每组数据的第一行是两个整数n(1 <= n <= 40),k(1 <= k <= 8)。 接着有k行,每行有两个整数a(1 <= a <= 8),b

2024年码蹄杯本科院校赛道初赛(省赛)

赛时所写题,简单写一下思路,qwq 第一题: 输出严格次小值, //#pragma GCC optimize(2)#include <iostream>#include <cstring>#include <algorithm>#include <vector>#include <queue>#include<stack>#include<cmath>#include <uno

Integer能表示十进制的多少位?

Java 提供两种不同的类型:引用类型和原始类型(或内置类型)。Int是java的原始数据类型,Integer是java为int提供的封装类。在32位机器上,能表示的最大值是2^32 = 4 294 967 296。 111111111111超过了最大表示范围,所以会报错。   超过了Integer的存值范围,Integer存值的范围是 -2的31次方 到 2的31次方-1 的常量   I

Integer 类型数据比较相等的那些坑

public void testInter() {Integer a = new Integer(200);Integer b = new Integer(200);Integer c = 200;Integer e = 200;int d = 200;Object o=200;System.out.println("基本类型和数字常量 ==判断"+(o==c));System.out.pr

第九届世界渲染大赛什么时候开始举办?

​第九届世界渲染大赛即将开启,全球设计师和艺术家将汇聚一堂,展现3D艺术的创新与美感。敬请期待这场业界顶级的视觉盛宴,让我们共同关注大赛的启幕时刻。 第九届世界渲染大赛开始时间 预计时间:2024年7月(中旬) 报名方法:移步 Renderbus瑞云渲染 B站官号了解或官网了解 根据以往的经验,世界渲染大赛每年都会如期而至,分别在春季和夏季各举办一次,每次赛事为期一个月。这一传统自