Codeforces Round #455 Div.2 909A

本文解析了CodeForces竞赛中一道A级题目,通过具体示例详细阐述了解题思路和算法实现过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Problem

http://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;
}



更多内容请关注微信公众号
wechat.jpg

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值