日常刷题

简介: 日常刷题

CodeForces - 1328C

A number is ternary if it contains only digits 0, 1and 2. For example, the following numbers are ternary: 1022, 11, 21, 2002.

You are given a long ternary number x. The first (leftmost) digit of x is guaranteed to be 2, the other digits of x can be 0, 1 or 2.

Let’s define the ternary XOR operation ⊙ of two ternary numbers a and b (both of length n) as a number c=a⊙b of length n, where ci=(ai+bi)%3 (where % is modulo operation). In other words, add the corresponding digits and take the remainders of the sums when divided by 3. For example, 10222⊙11021=21210.

Your task is to find such ternary numbers a and b both of length n and both without leading zeros that a⊙b=x and max(a,b) is the minimum possible.

You have to answer t independent test cases.

Input

The first line of the input contains one integer t (1≤t≤104) — the number of test cases. Then t test cases follow. The first line of the test case contains one integer n (1≤n≤5⋅104) — the length of x. The second line of the test case contains ternary number x consisting of n digits 0,1 or 2. It is guaranteed that the first digit of x is 2. It is guaranteed that the sum of n over all test cases does not exceed 5⋅104 (∑n≤5⋅104).

Output

For each test case, print the answer — two ternary integers a and b both of length n and both without leading zeros such that a⊙b=x and max(a,b) is the minimum possible. If there are several answers, you can print any.

Example

Input

4

5

22222

5

21211

1

2

9

220222021

Output

11111

11111

11000

10211

1

1

110111011

110111010

题目大致意思就是进行进制为三的不进位加法。比如2+2=2;找到两个数,使a+b=n;

不同的情况要进行不同的判定,

当前面分配的数字都相同的时候:2,分成(1,1),0分成(0,0),如何分配无所谓,但是1,分成(1,0)

如果前面分配的数字不同,即前面分配的有一位a>b,后面所有的数字都可以分给b

import java.util.Scanner;
public class c1 {
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int t=sc.nextInt();
    while(t-->0) {
      int n=sc.nextInt();
      String s=sc.next();
    char st[]= s.toCharArray();
    char pt1[]=new char[st.length];
    char pt2[]=new char[st.length];
    int flag=1;//判定
    for(int i=0;i<st.length;i++) {
    if(flag==1) {
      if(st[i]=='2') {
      pt1[i]='1';
      pt2[i]='1';
    }else if(st[i]=='1') {
      pt1[i]='1';
      pt2[i]='0';
      flag=0;
    }else if(st[i]=='0') {
      pt1[i]='0';
      pt2[i]='0';
    }
  }
    else {
      pt1[i]='0';
      pt2[i]=st[i];
    }
    }
    System.out.println(pt1);
    System.out.println(pt2);
    } 
}
}
相关文章
|
4天前
|
云安全 监控 安全
|
2天前
|
存储 机器学习/深度学习 人工智能
打破硬件壁垒!煎饺App:强悍AI语音工具,为何是豆包AI手机平替?
直接上干货!3000 字以上长文,细节拉满,把核心功能、使用技巧和实测结论全给大家摆明白,读完你就知道这款 “安卓机通用 AI 语音工具"——煎饺App它为何能打破硬件壁垒?它接下来,咱们就深度拆解煎饺 App—— 先给大家扒清楚它的使用逻辑,附上“操作演示”和“🚀快速上手不踩坑 : 4 条核心操作干货(必看)”,跟着走零基础也能快速上手;后续再用真实实测数据,正面硬刚煎饺 App的语音助手口令效果——创建京东「牛奶自动下单神器」口令 ,从修改口令、识别准确率到场景实用性,逐一测试不掺水,最后,再和豆包 AI 手机语音助手的普通版——豆包App对比测试下,简单地谈谈煎饺App的能力边界在哪?
|
9天前
|
机器学习/深度学习 人工智能 自然语言处理
Z-Image:冲击体验上限的下一代图像生成模型
通义实验室推出全新文生图模型Z-Image,以6B参数实现“快、稳、轻、准”突破。Turbo版本仅需8步亚秒级生成,支持16GB显存设备,中英双语理解与文字渲染尤为出色,真实感和美学表现媲美国际顶尖模型,被誉为“最值得关注的开源生图模型之一”。
1162 7
|
11天前
|
机器学习/深度学习 人工智能 数据可视化
1秒生图!6B参数如何“以小博大”生成超真实图像?
Z-Image是6B参数开源图像生成模型,仅需16GB显存即可生成媲美百亿级模型的超真实图像,支持中英双语文本渲染与智能编辑,登顶Hugging Face趋势榜,首日下载破50万。
734 42
|
15天前
|
人工智能 Java API
Java 正式进入 Agentic AI 时代:Spring AI Alibaba 1.1 发布背后的技术演进
Spring AI Alibaba 1.1 正式发布,提供极简方式构建企业级AI智能体。基于ReactAgent核心,支持多智能体协作、上下文工程与生产级管控,助力开发者快速打造可靠、可扩展的智能应用。
1176 41
|
15天前
|
人工智能 前端开发 算法
大厂CIO独家分享:AI如何重塑开发者未来十年
在 AI 时代,若你还在紧盯代码量、执着于全栈工程师的招聘,或者仅凭技术贡献率来评判价值,执着于业务提效的比例而忽略产研价值,你很可能已经被所谓的“常识”困住了脚步。
942 78
大厂CIO独家分享:AI如何重塑开发者未来十年
|
3天前
|
人工智能 安全 前端开发
AgentScope Java v1.0 发布,让 Java 开发者轻松构建企业级 Agentic 应用
AgentScope 重磅发布 Java 版本,拥抱企业开发主流技术栈。
|
2天前
|
人工智能 JSON 前端开发
为什么你的API文档总是被吐槽?用这份"契约指令"终结前后端战争
本文针对前后端协作中"文档过时、不准确"的痛点,提供了一套实战验证的AI指令。通过强制结构化输入和自检机制,让AI自动生成包含完整参数、JSON示例和多语言代码的标准API契约文档,彻底解决接口沟通难题。
172 112
|
11天前
|
存储 自然语言处理 测试技术
一行代码,让 Elasticsearch 集群瞬间雪崩——5000W 数据压测下的性能避坑全攻略
本文深入剖析 Elasticsearch 中模糊查询的三大陷阱及性能优化方案。通过5000 万级数据量下做了高压测试,用真实数据复刻事故现场,助力开发者规避“查询雪崩”,为您的业务保驾护航。
562 32