当前位置:网站首页>【暑期每日一题】洛谷 P3742 umi的函数
【暑期每日一题】洛谷 P3742 umi的函数
2022-07-01 04:47:00 【AC_Dragon】
题目链接:P3742 umi的函数 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
题目背景
umi 找到了一个神秘的函数 f。
题目描述
这个函数接受两个字符串 s1,s2。这些字符串只能由小写字母组成,并且具有相同的长度。这个函数的输出是另一个长度与 s1,s2 相同的字符串 g。g 的第 i 个字符等于 s1 的第i 个字符和 s2 的第 i 个字符的最小值,简单来说,g[i]=min(s1[i],s2[i])。
例如:f("ab","ba")= "aa", f("nzwzl","zizez")="niwel".
她现在有两个相同长度的只有小写字母的字符串 x,y。找出任何一个满足 f(x,z)=y 的
字符串 z。如果找不到这样的字符串的话,请输出-1。
输入格式
第一行给出以下两个字符串的长度 n。
第二行给出一个字符串 x。
第三行给出一个字符串 y。
输出格式
第一行输出一个字符串,代表你找到的符合条件的字符串。找不到的话,请输出-1。
样例 #1
样例输入 #1
2
ab
aa样例输出 #1
ba样例 #2
样例输入 #2
5
nzwzl
niwel样例输出 #2
xiyez样例 #3
样例输入 #3
2
ab
ba样例输出 #3
-1提示
对于 100%的数据,1<=n<=100。
AC code:
#include<iostream>
using namespace std;
int main()
{
int l;
cin>>l;
string s1,s2;
cin>>s1>>s2;
for(int i=0;i<l;i++)
{
if(s2[i]>s1[i])
{
cout<<-1;
return 0;
}
}
cout<<s2;
return 0;
} 边栏推荐
- LeetCode_53(最大子数组和)
- Basic usage, principle and details of session
- JVM栈和堆简介
- How do I sort a list of strings in dart- How can I sort a list of strings in Dart?
- 测量三相永磁同步电机的交轴直轴电感
- C#读写应用程序配置文件App.exe.config,并在界面上显示
- LeetCode_66(加一)
- 最长递增子序列及最优解、动物总重量问题
- 分布式全局唯一ID解决方案详解
- Strategic suggestions and future development trend of global and Chinese vibration isolator market investment report 2022 Edition
猜你喜欢

常用的Transforms中的方法

手动实现一个简单的栈

How to do the performance pressure test of "Health Code"
![AssertionError assert I.ndim == 4 and I.shape[1] == 3](/img/b1/0109bb0f893eb4c8915df36c100907.png)
AssertionError assert I.ndim == 4 and I.shape[1] == 3

VIM简易使用教程

JVM栈和堆简介

Pytoch (IV) -- visual tool visdom

LM small programmable controller software (based on CoDeSys) note 20: PLC controls stepping motor through driver

Use of dataloader

How to do the performance pressure test of "Health Code"
随机推荐
Maixll dock quick start
Pytorch(一) —— 基本语法
How to use maixll dock
I also gave you the MySQL interview questions of Boda factory. If you need to come in and take your own
STM32扩展板 数码管显示
Simple implementation of slf4j
Common UNIX Operation and maintenance commands of shell
JVM栈和堆简介
Common interview questions ①
Pytorch(三) —— 函数优化
Caijing 365 stock internal reference | the first IPO of Beijing stock exchange; the subsidiary of the recommended securities firm for gambling and gambling, with a 40% discount
2022 t elevator repair new version test questions and t elevator repair simulation test question bank
解决:Thread 1:[<*>setValue:forUndefinedKey]:this class is not key value coding-compliant for the key *
C#读写应用程序配置文件App.exe.config,并在界面上显示
Why is Internet thinking not suitable for AI products?
STM32 光敏电阻传感器&两路AD采集
C - detailed explanation of operators and summary of use cases
js解决浮点数相乘精度丢失问题
RuntimeError: mean(): input dtype should be either floating point or complex dtypes.Got Long instead
线程类的几大创建方法