sum is equal to the given integer number N and the second number
2011-11-08 19:20
375 查看
Description
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 file consists of a single integer N (10 <= N <= 10^9).
Output
On the first line of the output file write the total number of different pairs of integers that satisfy the problem statement.
On the following lines 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 X, Y, and N, must be replaced with the corresponding integer numbers. There should be exactly one space on both sides of '+' and '='
characters.
Sample Input
302
Sample Output
5
251 + 51 = 302
275 + 27 = 302
276 + 26 = 302
281 + 21 = 302
301 + 01 = 302
代码:
View Code
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 file consists of a single integer N (10 <= N <= 10^9).
Output
On the first line of the output file write the total number of different pairs of integers that satisfy the problem statement.
On the following lines 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 X, Y, and N, must be replaced with the corresponding integer numbers. There should be exactly one space on both sides of '+' and '='
characters.
Sample Input
302
Sample Output
5
251 + 51 = 302
275 + 27 = 302
276 + 26 = 302
281 + 21 = 302
301 + 01 = 302
代码:
View Code
#include <iostream> #include <math.h> using namespace std; void find(long int N) { int a[10]; int b[10]; for(int x=10;x<N;x++) { // cout<<x<<"\t"; long int total=0; a[0]=x/pow(10,9); //数x存在数组a中 for(int i=1;i<10;i++) { total+=a[i-1]*pow(10,10-i); a[i]=(x-total)/pow(10,(9-i)); } for(i=0;i<10&&a[i]==0;i++); //数x实际从第sign位开始 int sign=i; int len_x=10-sign; //len_x是数x实际再数组中存储的位数 for(int k=sign;k<10;k++) { long int y=0; for(int j=0,i=sign;j<len_x-1;j++,i++) //将数y存在数组b中 { if(k-sign==j) i++; b[j]=a[i]; y+=b[j]*pow(10,len_x-2-j); } // cout<<y<<"\t"; if(x+y==N) { cout<<x<<"+"; for(j=0;j<len_x-1;j++) cout<<b[j]; cout<<"="<<N<<endl; break; } } // cout<<endl; } } int main() { long int N; cout<<"input sum N(10<N<10^9):"; cin>>N; while(N<10||N>pow(10,9)) { cout<<"error!input again!"<<endl; cin>>N; } find(N); return 0; }
相关文章推荐
- I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum o
- There is integer array like {1,2,4,5,6,1,2,4,3,5,7,2,1}. I want to find the possible combination of pair which sum is 4.
- Row index must be greater than or equal to zero and less than the number of rows.
- Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example: Given the below binary tree andsum =
- 1TB is equal to the number of how many GB? 1PB equal to is equal to the number of TB? 1EB PB? | PC-fault.com
- [Grid Layout] Use auto-fill and auto-fit if the number of repeated grid tracks is not to be def
- Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive
- How to arrange 10 digits so that the product of the some of them is equal to a number represented by the remaining digits
- Given the numbers 1 to 1000, what is the minimum number?
- Finding all elements(which are integer) in an array whose sum is equals to the element exists within
- How to arrange 10 digits so that the product of the some of them is equal to a number represented by the remaining digits
- The connection to adb is down, and a severe error has occured.
- The connection to adb is down, and a severe error has occured.
- The connection to adb is down, and a severe error has occured.
- The connection to adb is down, and a severe error has occured.
- Your task is to find for a given phone number any of its divisions into groups of two or three digit
- eclipse The connection to adb is down, and a severe error has occured 解决方法
- 【译】Why JavaScript Is and Will Continue to Be the First Choice of Programmers
- 关于android:The connection to adb is down, and a severe error has occured.
- Android 提示: The connection to adb is down, and a severe error has occured.