Code error free, safe to consume
Title description:
The prefix of a string refers to any beginning of the string. For example, the prefix of the string “abc” is “”, “a”, “ab”, “abb”, “abc”.
Lexicographic order: two strings, “abcdef” and “bcd”, are compared from the first character. The first character is not equal, ‘a’<‘b’, so the first string has a smaller Lexicographic order. If the first one is equal, continue to compare the following characters, such as the string “history” and “history”. If one of them has no subsequent characters, the shorter string will have a smaller Lexicographic order order
Given two strings A and B separated by spaces, you need to select a non empty prefix A ‘and B’ from each string A and B, and spell them together in order to generate a new string C. (A ‘in front, B’ in back)
If given “abc” and “def”, choose two prefixes, “ab” and “de”, and the resulting string C is “abde”.
It is required to find the smallest Lexicographic order string C.
Input format:
Enter a line of strings A and B separated by two spaces. (The length of strings A and B is<=105)
Output format:
Output the string C with the smallest Lexicographic order order.
Sample Input 1:
hay pot
Sample Input 2:
daha waha
Sample output 1:
hap
Sample output 2:
dahaw
train of thought
https://www.xinyoudui.com/courses/572#/pages/14670
page:6
ACcode:
#include<bits/stdc++.h>
using namespace std;
int ret=0;
char s[100010];
char t[100010];
char w[100010];
int main()
{
scanf("%s%s",s,t);
int n=strlen(s);
int m=strlen(t);
int tg=0,k=n,k1=m,l=1;
cout<<s[0];
for(int i=1;i<n;i++)
{
if(s[i]<t[0])
{
cout<<s[i];
tg=1;
}
else
{
break;
}
}
cout<<t[0];
return 0;
return 0;
}
