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

bases , but he keeps making errorssince he is only 6 years old. Whenever XiaoMing converts a

number to a new base and writes downthe result, he always writes one of the digits wrong.

For example , if he converts thenumber 14 into binary (i.e., base 2), the correct result should be

"1110", but he mightinstead write down "0110" or "1111". XiaoMing neveraccidentally adds or

deletes digits, so he might writedown a number with a leading digit of " 0" if this is the digit she

gets wrong.

Given XiaoMing 's output whenconverting a number N into base 2 and base 3, please determine

the correct original value of N (inbase 10). (N<=10^10)

You can assume N is at most 1billion, and that there is a unique solution for N.

Input

The first line of the input containsone integers T, which is the nember of test cases (1<=T<=8)

Each test case specifies:

* Line 1: The base-2 representationof N , with one digit written incorrectly.

* Line 2: The base-3 representationof N , with one digit written incorrectly.

Output

For each test case generate a singleline containing a single integer ,  the correct value of N

Sample Input

1 1010 212

Sample Output

14

题意多实例,然后每个样例给两行字符串分别是2进制的和3进制的,表示的是同一个十进制数。但是每个串都是有一个数是错的,让你通过这两个错的来找出呢个正确的十进制数。暴力找出所有情况的十进制数,然后一一对比相等说明这个十进制数就是正确的要求的数。

具体看代码,不算太难只不过中间一些小细节特别需要注意:

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<time.h>
#include<iostream>
#include<ctype.h>
#include<map>
#include<set>
#include<string>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<queue>
#include<stack>
using namespace std;
int a[];
int b[];
char s[];
char s0[];
int h=,k=,len1,len2;
int f(int t)//将2进制转换为十进制存起来
{
int i;
int sum=;
for(i=; i<=len1; i++)//主意为什么此处是小于等于,main函数有解释
{
sum+=pow(,t)*(s[i]-'');
t--;
}
a[k++]=sum;
}
int ff(int t)//将3进制转换为十进制存起来
{
int i,sum=;
for(i=; i<=len2; i++)
{
sum+=pow(,t)*(s0[i]-'');
t--;
}
b[h++]=sum;
}
int main()
{
int t;
char cc,cc2;
int i,j;
scanf("%d",&t); while(t--)
{
//getchar(); scanf("%s",s);
scanf("%s",s0);
len1=strlen(s)-;//这个地方本来想着减不减无所谓,循环的时候控制一下就行
len2=strlen(s0)-;//但是试了好几次,只有用这个,然后循环变成<=才能出数据,可能因为用char的话最后一位会自动赋值一个\0表示结束吧,然后中间运行会莫名出现问题,具体啥问题我也不清楚,但是很神奇,计算到前一位就过了
h=;
k=;
for(i=; i<=len1; i++)//列举2进制串所有可能情况
{
cc=s[i];
if(s[i]=='')
s[i]='';
else
s[i]='';
f(len1);
s[i]=cc;
}
for(i=; i<=len2; i++)//列举3进制串所有可能情况
{
cc2=s0[i];
if(s0[i]=='')
{
s0[i]='';
ff(len2);
s0[i]='';
ff(len2);
}
else if(s0[i]=='')
{
s0[i]='';
ff(len2);
s0[i]='';
ff(len2);
}
else
{
s0[i]='';
ff(len2);
s0[i]='';
ff(len2);
}
s0[i]=cc2;
}
for(i=; i<k; i++)
{
for(j=; j<h; j++)
{
if(a[i]==b[j])
{
printf("%d\n",a[i]);
break;
}
}
}
memset(s,,sizeof(s));
memset(s0,,sizeof(s0));
}
}

NYOJ 1277Decimal integer conversion (第九届河南省省赛)的更多相关文章

  1. nyoj 1274信道安全 第九届河南省赛(SPFA)

    信道安全 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 Alpha 机构有自己的一套网络系统进行信息传送.情报员 A 位于节点 1,他准备将一份情报 发送给位于节点 ...

  2. 『NYIST』第九届河南省ACM竞赛队伍选拔赛[正式赛二]-最小内积(第八届北京师范大学程序设计竞赛决赛)

    H. 最小内积                                                                   Time Limit: 1000ms Memory ...

  3. 『NYIST』第九届河南省ACM竞赛队伍选拔赛[正式赛二]- Nearly Lucky Number(Codeforces Beta Round #84 (Div. 2 Only)A. Nearly)

    A. Nearly Lucky Number time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  4. 『NYIST』第九届河南省ACM竞赛队伍选拔赛[正式赛二]--Codeforces -35D. Animals

    D. Animals time limit per test 2 seconds memory limit per test 64 megabytes input input.txt output o ...

  5. nyoj1273 河南省第九届省赛_"宣传墙"、状压DP+矩阵幂加速

    宣传墙 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 ALPHA 小镇风景美丽,道路整齐,干净,到此旅游的游客特别多.CBA 镇长准备在一条道路南 面 4*N 的墙上做 ...

  6. NYOJ 1272 表达式求值 第九届省赛 (字符串处理)

    title: 表达式求值 第九届省赛 nyoj 1272 tags: [栈,数据结构] 题目链接 描述 假设表达式定义为: 1. 一个十进制的正整数 X 是一个表达式. 2. 如果 X 和 Y 是 表 ...

  7. 河南省acm第九届省赛--《表达式求值》--栈和后缀表达式的变形--手速题

    表达式求值 时间限制:1000 ms | 内存限制:65535 KB 难度:3   描述 假设表达式定义为:1. 一个十进制的正整数 X 是一个表达式.2. 如果 X 和 Y 是 表达式,则 X+Y, ...

  8. 第七届河南省赛H.Rectangles(lis)

    10396: H.Rectangles Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 229  Solved: 33 [Submit][Status] ...

  9. 第七届河南省赛10403: D.山区修路(dp)

    10403: D.山区修路 Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 69  Solved: 23 [Submit][Status][Web Bo ...

随机推荐

  1. bzoj1663: [Usaco2006 Open]赶集

    Description Every year, Farmer John loves to attend the county fair. The fair has N booths (1 <= ...

  2. 关于我在17号“一个查询任意年份中任意月份的天数”程序编写中的代码&第二种方法!

    PS:下面的代码是我对于17号的练习题的一些新的看法(其实就是从另一个角度思考问题) package day20180917;import java.util.Scanner;//导包public c ...

  3. oracle审计例子

    1.数据库开启审计alter system set audit_trail=db,extended scope=spfile;shutdown immediatestartup 2.对某个表进行审计c ...

  4. Idea 破解教程 (2018.11-29最新版)

    一.下载安装idea,这里不做赘述.官网-https://www.jetbrains.com/idea/ 二.安装完idea后,需要激活使用.这里需要先下载个工具包 ,下载网址http://idea. ...

  5. redhat7.4+shell离线安装docker

    首先要准备离线安装包 1.docker官网下载 2.docker-compose gitbub官网下载 3.我的docker-compose install-docker.sh #!/bin/sh u ...

  6. Black Hat Python3 Chapter4

    mail sniffer 现在的邮箱应用我能找到的都是加密传输了,因此相像书中那样直接从抓到的包里获取到用户名和密码信息除非是自己专门搭建一个邮箱服务器,不然很难做到,为了便于理解代码的运行,多添加一 ...

  7. C语言动态链表数据结构

    链表的操作增删改查 typedef int DATA; struct SNode { DATA data; SNode* pNext; }; SNode* g_head=NULL;//全局变量 //从 ...

  8. Bootstrap3基础 form-horizontal 表单元素横向布局 简单示例

      内容 参数   OS   Windows 10 x64   browser   Firefox 65.0.2   framework     Bootstrap 3.3.7   editor    ...

  9. Bootstrap3基础 btn-primary/warning... 三类按钮的六种样式

      内容 参数   OS   Windows 10 x64   browser   Firefox 65.0.2   framework     Bootstrap 3.3.7   editor    ...

  10. selinux权限问题【转】

    本文转载自:https://blog.csdn.net/u011386173/article/details/83339770 版权声明:本文为博主原创文章,未经博主允许不得转载. https://b ...