1077 Kuchiguse (20分)

本文探讨了日语中独特的句子结尾粒子,这些粒子反映了说话者的个性。通过分析动漫和漫画中角色的语言习惯,即“Kuchiguse”,文章提供了一个算法,用于识别并找出角色对话中的共同后缀,以此来确定其语言偏好。

The Japanese language is notorious for its sentence ending particles. Personal preference of such particles can be considered as a reflection of the speaker's personality. Such a preference is called "Kuchiguse" and is often exaggerated artistically in Anime and Manga. For example, the artificial sentence ending particle "nyan~" is often used as a stereotype for characters with a cat-like personality:

  • Itai nyan~ (It hurts, nyan~)

  • Ninjin wa iyada nyan~ (I hate carrots, nyan~)

Now given a few lines spoken by the same character, can you find her Kuchiguse?

Input Specification:

Each input file contains one test case. For each case, the first line is an integer N (2≤N≤100). Following are N file lines of 0~256 (inclusive) characters in length, each representing a character's spoken line. The spoken lines are case sensitive.

Output Specification:

For each test case, print in one line the kuchiguse of the character, i.e., the longest common suffix of all N lines. If there is no such suffix, write nai.

Sample Input 1:

3
Itai nyan~
Ninjin wa iyadanyan~
uhhh nyan~

Sample Output 1:

nyan~

Sample Input 2:

3
Itai!
Ninjinnwaiyada T_T
T_T

Sample Output 2:

nai

题意:找最大相同的后缀

思路:用vector容器储存字符串,两个循环搞定,外循环,所有字符串最小长度,内循环,每个字符串的最后一位字符是否相等,维护一个string来保存相等的字符,只要有一个不相等,直接跳出两层循环,然后判断string是否为空,若为空,则说明没有相同的后缀,反之,将string逆序输出即可~

#include<iostream>

#include<vector>
#include<algorithm>


using namespace std;

int main(){
    int n;
    cin >> n;
    vector<string> vec(n);
    char c;
    c = getchar();
    int min_len = 0x7fffffff;
    for(int i = 0; i < n; i++){

        getline(cin, vec[i]);
        min_len = min(min_len, int(vec[i].length()));
    }
    string s = "";
    char temp;
    bool  flag = true;
    for(int j = 1; j <= min_len; j++){
        for(int i = 0; i < n - 1; i++){

            if(vec[i][vec[i].length() - j] != vec[i + 1][vec[i + 1].length() - j]){
                flag = false;
                break;
            }

            temp = vec[i][vec[i].length() - j];
        }
        if(flag){
            s += temp;
        }else
        {
            break;
        }
        
            


    }
    
    reverse(s.begin(), s.end());
    if(s == ""){
        cout << "nai" << endl;
    }else
    {
        cout << s << endl;
    }
    
    

    return 0;
}

 

【路径规划】(螺旋)基于A星全覆盖路径规划研究(Matlab代码实现)内容概要:本文围绕“基于A星算法的全覆盖路径规划”展开研究,重点介绍了一种结合螺旋搜索策略的A星算法在栅格地图中的路径规划实现方法,并提供了完整的Matlab代码实现。该方法旨在解决移动机器人或无人机在未知或部已知环境中实现高效、无遗漏的区域全覆盖路径规划问题。文中详细阐述了A星算法的基本原理、启发式函数设计、开放集与关闭集管理机制,并融合螺旋遍历策略以提升初始探索效率,确保覆盖完整性。同时,文档提及该研究属于一系列路径规划技术的一部,涵盖多种智能优化算法与其他路径规划方法的融合应用。; 适合人群:具备一定Matlab编程基础,从事机器人、自动化、智能控制及相关领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①应用于服务机器人、农业无人机、扫地机器人等需要完成区域全覆盖任务的设备路径设计;②用于学习和理解A星算法在实际路径规划中的扩展应用,特别是如何结合特定搜索策略(如螺旋)提升算法性能;③作为科研复现与算法对比实验的基础代码参考。; 阅读建议:建议结合Matlab代码逐段理解算法实现细节,重点关注A星算法与螺旋策略的切换逻辑与条件判断,并可通过修改地图环境、障碍物布等方式进行仿真实验,进一步掌握算法适应性与优化方向。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值