问题 : Decimal integer conversion

时间限制: 1 Sec  内存限制: 128 MB

题目描述

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

解题思路

水题,直接暴力,把所有的情况都跑一遍就可以了。

 #include <stdio.h>
 #include <string.h>
 int main()
 {
     int t, A, B, lena, lenb, temp;
     ], b[];
     scanf("%d%*c", &t);
     while (t--)
     {
         temp = ;
         scanf("%s%s", a, b);
         lena = strlen(a);
         lenb = strlen(b);
         ; i < lena; i++)
         {
             A = ;
             a[i] = (a[i] - ) %  + ';
             ; j < lena; j++)
                 A = A *  + a[j] - ';
             a[i] = (a[i] - ) %  + ';
             ; j < lenb; j++)
             {
                 B = ;
                 b[j] = (b[j] - ) %  + ';
                 ; k < lenb; k++)
                     B = B *  + b[k] - ';
                 if (A == B)
                 {
                     temp = ;
                     break;
                 }
                 B = ;
                 b[j] = (b[j] - ) %  + ';
                 b[j] = (b[j] - ) %  + ';
                 ; k < lenb; k++)
                     B = B *  + b[k] - ';
                 if (A == B)
                 {
                     temp = ;
                     break;
                 }
                 b[j] = (b[j] - ) %  + ';
             }
             if (temp)
                 break;
         }
         printf("%d\n", A);
     }
     ;
 }

Decimal integer conversion的更多相关文章

  1. NYOJ 1277Decimal integer conversion (第九届河南省省赛)

    XiaoMing likes mathematics, and heis just learning how to convert numbers between different bases , ...

  2. log4j:ERROR Category option " 1 " not a decimal integer.错误解决

    log4j.properties 的配置文件中: log4j.appender.stdout.layout.ConversionPattern =  %d{ABSOLUTE} %5p %c{ 1 }: ...

  3. 每天一套题打卡|河南省第九届ACM/ICPC

    A 表达式求值 表达式求值:可以用递归求解,也可以用栈模拟,考过多次. 类似题目:NYOJ305,NYOJ35 用栈模拟做法: #include <stdio.h> #include &l ...

  4. java.lang.Integer源码浅析

    Integer定义,final不可修改的类 public final class Integer extends Number implements Comparable<Integer> ...

  5. 使用parquet-hadoop.jar包解析hive parquet文件时,遇到FIXED_LEN_BYTE_ARRAY转换为Decimal 以及 INT96转换为timestamp问题

    在使用parquet-hadoop.jar包解析parquet文件时,遇到decimal类型的数据为乱码,具体解决方法如下: 使用parquet-Hadoop.jar解析httpfs服务提供的parq ...

  6. Conversion Specifiers and the Resulting Printed Output

    Conversion Specification Output %a Floating-point number, hexadecimal digits and p-notation (C99). % ...

  7. The integer promotion.

    Usual Arithmetic Conversion: The integer promotions are performed on both operands. Then the followi ...

  8. java的toString()及包装类的实现--Integer重点学习

    1. toString()来源 2. toString()目的 3. toString()实现(JDK8) 1. toString()来源 源于java.lang.Object类,源码如下: /** ...

  9. LeedCode OJ -- String to Integer (atoi)

    点击打开题目链接 题目意思就是自己实现一个atoi函数,也就是将字符串转换成int型. 关于INT_MAX和INT_MIN, 只是在<limits.h>文件中定义的宏..分别是int型可以 ...

随机推荐

  1. VGGNet学习——实践

    0 - DataSet http://www.csc.kth.se/~att/Site/Animals.html 1 - Code 1.1 - Import Packages import tenso ...

  2. SpringSocial业务系统与社交网站的绑定与解绑

    SpringSocial提供了了以下三个服务,我们要做的仅仅是调用它们的服务,但是SpringSocial仅仅只提供了数据,没有提供视图 ⒈拿到所有社交网站与业务系统的绑定信息 SpringSocia ...

  3. Elasticsearch 5.4.3实战--Java API调用:索引mapping创建

    因为项目开发使用的是Java语言, 项目的开发架构是Spring MVC+ maven的jar包管理,  所以今天重点说说ES 5.4.3 的Java API的源码实战 1. pom.xml文件增加依 ...

  4. python2x与python3x的区别

    python2x与Python3x的区别 一.1.Python2x: a.源码不规范,源码混乱,重复代码冗余(重复多) python3x: b.重整源码,源码规范,优美,清新,简单 2.Python2 ...

  5. linux添加swap分区【转】

    概述 添加交换分区主要是因为安装oracle时碰到交换分区太小时无法安装的情况,这时候就需要添加交换分区了. 操作简介 增加swap分区方法: 1.新建磁盘分区作为swap分区 2.用文件作为swap ...

  6. shell 在手分析服务器日志【转】

    自己的小网站跑在阿里云的 ECS 上面, 偶尔也去分析分析自己网站服务器日志,看看网站的访问量.看看有没有黑阔搞破坏!于是收集,整理一些服务器日志分析命令,大家可以试试! awk '{print $1 ...

  7. 题解-APIO2010 特别行动队

    题目 洛谷 & bzoj 简要题意:给定一个长为\(n\)的序列\(\{s_i\}\)与常数\(a,b,c\),序列的一个连续子段\(s_i\)到\(s_j\)的贡献为\(at^2+bt+c\ ...

  8. Java内置包装类

    Java内置包装类有Object.Integer.Float.Double.Number.Charcter.Boolean.Byte.System. Number,是抽象类,也是超类(父类).Numb ...

  9. 执行原生SQL语句的方式

    原生sql语句 cursor方法:from api.models import *from django.db import connection,connectionscursor=connecti ...

  10. Tornado学习笔记(三) 请求方式/状态码

    本章我们来学习 Tornado 支持的请求方式 请求方式 Tornado支持任何合法的HTTP请求(GET.POST.PUT.DELETE.HEAD.OPTIONS).你可以非常容易地定义上述任一种方 ...