CF909A Generate Login

题意翻译

给定两个用空格分隔的字符串,分别取两字符串的任意非空前缀,将两前缀合并为一个新的字符串,求可行字典序最小的字符串。

题目描述

The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person.

You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users).

As a reminder, a prefix of a string ss is its substring which occurs at the beginning of ss : "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string aa is alphabetically earlier than a string bb , if aa is a prefix of bb , or aa and bb coincide up to some position, and then aa has a letter that is alphabetically earlier than the corresponding letter in bb : "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac".

输入输出格式

输入格式:

 

The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive.

 

输出格式:

 

Output a single string — alphabetically earliest possible login formed from these names. The output should be given in lowercase as well.

 

输入输出样例

输入样例#1: 复制
harry potter
输出样例#1: 复制
hap
输入样例#2: 复制
tom riddle
输出样例#2: 复制
tomr
 
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
string s1,s2;
int len1,len2,pos1,pos2;
int main(){
    cin>>s1>>s2;
    len1=s1.length()-1;
    len2=s2.length()-1;pos1=1;
    while(s1[pos1]<s2[pos2]&&pos1<=len1)    pos1++;
    if(pos1){
        for(int i=0;i<pos1;i++)    cout<<s1[i];
        cout<<s2[0];
        return 0;
    }
}
 
细雨斜风作晓寒。淡烟疏柳媚晴滩。入淮清洛渐漫漫。 雪沫乳花浮午盏,蓼茸蒿笋试春盘。人间有味是清欢。
原文地址:https://www.cnblogs.com/cangT-Tlan/p/8440424.html