codeforces B. Sum of Two Numbers

 一、题目:

B. Sum of Two Numbers

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

The sum of digits of a non-negative integer a is the result of summing up its digits together when written in the decimal system. For example, the sum of digits of 123123 is 66 and the sum of digits of 1010 is 11. In a formal way, the sum of digits of a=∑i=0∞ai⋅10i=∑=0∞⋅10, where 0≤ai≤90≤≤9, is defined as ∑i=0∞ai∑=0

Given an integer n, find two non-negative integers x and y which satisfy the following conditions.

  • x+y=n+=, and
  • the sum of digits of x and the sum of digits of y differ by at most 11.

It can be shown that such xand y always exist.

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤100001≤≤10000).

Each test case consists of a single integer n (1≤n≤1091≤≤109)

Output

For each test case, print two integers x and y.

If there are multiple answers, print any.

Example

input

Copy

5
1
161
67
1206
19

output

Copy

1 0
67 94
60 7
1138 68
14 5

Note

In the second test case, the sum of digits of 6767 and the sum of digits of 9494 are both 1313.

In the third test case, the sum of digits of 6060 is 66, and the sum of digits of 77 is 77.

二、思路:

拆分每一数,偶数上下分得相同,奇数大的先分到下面,下一位奇数时大的分到上面。


三、代码:

#include<iostream>
using namespace std;
char a[2000000];
int main()
{
	int t;
	cin >> t;
	
	while (t--) {
		cin >> a;
		int x = 0, y = 0, flat = 0;
		for (int i = 0; a[i] != '\0'; i++) {
			if (a[i] % 2 == 0) {
				x = x * 10 + (a[i] - '0') / 2;
				y = y * 10 + (a[i] - '0') / 2;
			}
			else {
				if (flat == 0) {
					x = x * 10 + (a[i] - '0') / 2;
					y = y * 10 + (a[i] - '0') / 2 + 1;
					flat = 1;
				}
				else {
					if (flat == 1) {
						x = x * 10 + (a[i] - '0') / 2 + 1;
						y = y * 10 + (a[i] - '0') / 2;
						flat = 0;
					}
 
				}
 
 
			}
 
 
		}
		cout << x << " " << y << endl;
 
	}
 
 
 
 
 
 
 
 
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值