贪心解析2 c++

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;

}

1 个赞

???

1 个赞

What’s wrong??

1 个赞

英文?
你认真的?

1 个赞

Can’t we???

1 个赞

数组中子段的最大总和。

例如,1 2 3 -5 4 3 -6 中的最大子段总和是 1 + 2 + 3 +( - 5)+ 4 + 3 = 8

输入格式:

第一行中的整数 n

第二行 n 个整数

输出格式:

一个整数表示最大字段和

样例输入:

7 1 2 3 -5 4 3 -6

样例输出:

8

约定:

1≤n≤100000,−10000≤序列元素≤10000

1 个赞