Codeforces Round #455 Div.2 909A

Правка en3, от zhenghaishu, 2017-12-29 09:59:59

Problem

http://mirror.codeforces.com/contest/909/problem/A

Analysis

According to the problem statements, you need to consider all the characters in the first name, and only the first character in the last name.

(1) Take “harry potter”for example

① You got“hp”

② You got “hap”, which is less than “hp”

③ You got “harp”,which is greater than “hap”

So, the answer is “hap”

(2) Take“ertuyivhfg v”for example

① You got “ev”

② You got “erv”, which is less than “ev”

③ You got “ertv”, which is less than “erv”

④ You got “ertuv”, which is less than “ertv”

⑤ You got “ertuyv”, which is greater than “ertuv”

So, the answer is “ertuv”

Code

#include<iostream>
#include<string>
using namespace std;

int main() 
{
	char first[10], last[10];
	cin >> first;
	cin >> last;
	
	string pre1, pre2, temp, result;
	pre1 = "";
	pre1 += first[0];
	pre2 = "";
	pre2 += last[0];
	result = pre1 + pre2;
	
	for (int i = 1; first[i]; i++) 
	{
		pre1 += first[i];
		temp = pre1 + pre2;
	
		if (temp < result)
		{
			result = temp;
		}
	}
	
	cout << result;
}

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский zhenghaishu 2017-12-29 09:59:59 16
en2 Английский zhenghaishu 2017-12-29 09:59:14 4
en1 Английский zhenghaishu 2017-12-29 09:57:38 1123 Initial revision (published)