Pairs of Integers

You are to find all pairs of integers such that their sum is equal to the given integer number N and the second number results from the first one by striking out one of its digits. The first integer always has at least two digits and starts with a non-zero digit. The second integer always has one digit less than the first integer and may start with a zero digit.

Input

The input consists of a single integer N (10 ≤ N ≤ 10 9).

Output

Write the total number of different pairs of integers that satisfy the problem statement. Then write all those pairs. Write one pair on a line in ascending order of the first integer in the pair. Each pair must be written in the following format:
X + Y = N
Here XY, and N must be replaced with the corresponding integer numbers. There should be exactly one space on both sides of '+' and '=' characters.

Example

input output
302
5
251 + 51 = 302
275 + 27 = 302
276 + 26 = 302
281 + 21 = 302
301 + 01 = 302

//题意是,给出一个数,问有哪些数少掉某一位,与原数相加可得这个数,列出所有情况,第一个加数不能有前导 0 ,后一个可以有,

还有,重复的情况只能输出一个 比如 455 + 55 = 510 去掉 455 第一个5,和第二个5都能得510 ,只要输出一次就可以了

//做过类似的题目,用数学方法做,比较快。http://www.cnblogs.com/haoabcd2010/p/5991009.html

不过这题有点不一样,要按第一个数大小排序,还要去掉重复的,还要记得在第二个加数可能要补0 ,不过这都是些小问题。。。

15ms 比较快

 #include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std; struct Num
{
int a,b;
int z;
}num[];
int t; bool cmp(Num x,Num y)
{
return x.a<y.a;
} void read(int x,int y)
{
int a=x,b=y;
int lenx=,leny=;
while (a!=)
{
lenx++;
a/=;
}
while (b!=)
{
leny++;
b/=;
}
if (y==) leny=;
num[t].a=x;
num[t].b=y;
num[t].z=lenx--leny;
t++;
} int main()
{
int N;
while (scanf("%d",&N)!=EOF)
{
t=;
for (int i=;i<=N;i*=)
{
int a=N/i/;
int b=N/i%; if (b<)
{
int c=(N-N/i*i)/;
if ((*a+b)*i+*c==N)
read( (*a+b)*i+c , a*i+c );
}
b--;
if (a+b&&b>=)
{
int c=(N-N/i*i+i)/;
if ((*a+b)*i+*c==N)
read( (*a+b)*i+c , a*i+c );
}
}
sort(num,num+t,cmp);
int real_t=;
for (int i=;i<t;i++)
{
if (i!=&&num[i].a==num[i-].a) continue;
real_t++;
}
printf("%d\n",real_t);
for (int i=;i<t;i++)
{
if (i!=&&num[i].a==num[i-].a) continue;
printf("%d + ",num[i].a);
for (int j=;j<num[i].z;j++)
printf("");
printf("%d = %d\n",num[i].b,N);
}
}
return ;
}

Pairs of Integers的更多相关文章

  1. POJ 1117 Pairs of Integers

    Pairs of Integers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4133 Accepted: 1062 Des ...

  2. 2018牛客网暑期ACM多校训练营(第一场) J - Different Integers - [莫队算法]

    题目链接:https://www.nowcoder.com/acm/contest/139/J 题目描述  Given a sequence of integers a1, a2, ..., an a ...

  3. Different Integers 牛客多校第一场只会签到题

    Given a sequence of integers a1, a2, ..., an and q pairs of integers (l1, r1), (l2, r2), ..., (lq, r ...

  4. 牛客暑假多校第一场J-Different Integers

    一.题目描述: 链接:https://www.nowcoder.com/acm/contest/139/JGiven a sequence of integers a1, a2, ..., an an ...

  5. 牛客网暑期ACM多校训练营(第一场) - J Different Integers(线段数组or莫队)

    链接:https://www.nowcoder.com/acm/contest/139/J来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 524288K,其他语言1048 ...

  6. Codeforces Round #562 (Div. 2) B. Pairs

    链接:https://codeforces.com/contest/1169/problem/B 题意: Toad Ivan has mm pairs of integers, each intege ...

  7. Different Integers 牛客网暑期ACM多校训练营(第一场) J 离线+线状数组或者主席树

    Given a sequence of integers a1, a2, ..., an and q pairs of integers (l 1, r1), (l2, r2), ..., (lq, ...

  8. Different Integers

    牛客一 J题 树状数组 题目描述 Given a sequence of integers a1, a2, ..., an and q pairs of integers (l1, r1), (l2, ...

  9. Vector Tile

    Mapbox Vector Tile Specification A specification for encoding tiled vector data. <?XML:NAMESPACE ...

随机推荐

  1. Oracle数据库实现获取前几条数据的方法

    如何在Oracle数据库中实现获取前几条数据的方法呢?就是类似SQL语句中的SELECT TOP N的方法.本文将告诉您答案,举例说明了哟!   1.在Oracle中实现SELECT TOP N : ...

  2. 倍福TwinCAT(贝福Beckhoff)基础教程5.1 TwinCAT-2 运行可执行文件

    个人认为这条命令做的参数比较混乱,PATHSTR是指可执行文件路径+最终文件名,DIRNAME是指可执行文件路径,最后COMNDLINE可有可无,是指带参数运行启动的文件   测试可以正常运行     ...

  3. Java List具体解释

    List接口是Collection的子接口,用于定义线性表结构,当中ArrayList能够理解为一个动态数组,而LinkedList能够理解为一个链表 经常使用操作: 插入和删除操作: void ad ...

  4. Codeforces Round #262 (Div. 2)解题报告

    详见:http://robotcator.logdown.com/posts/221514-codeforces-round-262-div-2 1:A. Vasya and Socks   http ...

  5. Pro Tools安装图文教程

    Pro Tools安装图文教程   Avid Pro Tools是Digidesign公司出品的一款音质最佳.音频制作强大的软件,能够在Mac或PC上为影片编曲.录制.编辑和混制高品质音乐或声音,生成 ...

  6. eclispe查看jdk源码后特别卡顿导致未响应解决

    第一步:Eclipse -> Preferences -> General -> Startup and Shutdown.不要勾选 RSE UI. 第二步:Eclipse -> ...

  7. react-navigation-easy-helper

    本组件旨在不更改源码情况下,简单配置即可实现一些复杂的功能.如在任意位置进行跳转.根据路由名字返回指定页面.简化参数的获取.快速点击的拦截.统一页面跳转的拦截等. 安装: npm install re ...

  8. Python的Django框架中的Cookie相关处理

    Python的Django框架中的Cookie相关处理 浏览器的开发人员在非常早的时候就已经意识到. HTTP's 的无状态会对Web开发人员带来非常大的问题,于是(cookies)应运而生. coo ...

  9. 【BIEE】由于排序顺序不兼容,集合操作失败

    问题描述 使用BIEE数据透视表时,使用了UNION进行数据组合,但是在浏览结果时意外出错了,报错如下截图: 问题分析 原因暂时未知 问题解决 目前使用UNION进行聚合,只需要将UNION修改为UN ...

  10. 【Lucene】Apache Lucene全文检索引擎架构之入门实战1

    Lucene是一套用于全文检索和搜寻的开源程式库,由Apache软件基金会支持和提供.Lucene提供了一个简单却强大的应用程式接口,能够做全文索引和搜寻.在Java开发环境里Lucene是一个成熟的 ...