PAT 1077. Kuchiguse
这个题目写不出,完全是C++语法不熟,
(1)读入一行字符串:getline(cin, s);
(2)字符串的反转:reverse(s.begin(), s.end());
(3)字符串取出某个字符:s[i]
1077. Kuchiguse (20)
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
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>using namespace std;int main()
{int n;string s, ans;vector<string> v;cin >> n;getchar();while(n--) {getline(cin, s);reverse(s.begin(), s.end());v.push_back(s);}string s1 = v[0];for(int i=0; i<s1.size(); i++) {bool f = true;for(int j=1; j<v.size(); j++) {if(v[j][i] != s1[i]) {f = false;break;}}if(f)ans += s1[i];elsebreak;}if(ans.empty())cout << "nai" << endl;else {reverse(ans.begin(), ans.end());cout << ans << endl;}return 0;
}
PAT 1077. Kuchiguse相关推荐
- PAT甲级1077 Kuchiguse:[C++题解]字符串、最长公共后缀
文章目录 题目分析 题目链接 题目分析 来源:acwing 分析: 读入n个字符串s[n],以s[0]为基础找公共后缀.枚举后缀的长度,内层循环遍历其他字符串,判断是否后缀相等. 使用子串的函数sub ...
- 1077 Kuchiguse (20point(s)) - C语言 PAT 甲级
1077 Kuchiguse (20point(s)) The Japanese language is notorious for its sentence ending particles. Pe ...
- 1077.Kuchiguse (20)
1077.Kuchiguse (20) pat-al-1077 2017-01-27 本题无坑 方法:把字符串一个一个读进来,每个都逆序一下,并且在这个过程中记录一下最短的字符串的长度:然后开始对每个 ...
- 1077. Kuchiguse (20)-PAT甲级真题
The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...
- PAT甲题题解-1077. Kuchiguse (20)-找相同后缀
#include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...
- PAT (Advanced) 1077. Kuchiguse (20)
随便写了个,比较啰嗦. 下次有机会找找好的方法. #include <iostream> #include <string> #include <cstring> ...
- 1077.Kuchiguse(20分)
The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...
- 1077. Kuchiguse (20)
题目如下: The Japanese language is notorious for its sentence ending particles. Personal preference of s ...
- 1077 Kuchiguse
题目大意: 输出n个字符串的最长公共后缀,没有就输出"nai". 解题思路: 首先比较前两个找出公共后缀,然后依次和后面的字符串比较,维护公共后缀即可.或者也可以顺序两两比较维护一 ...
最新文章
- 对于今年AI电磁组的一些看法
- Linux复习资料——MySQL-client-5.6.50-1.el7.x86_64与MySQL-server-5.6.50-1.el7.x86_64包安装MySQL全过程
- linux监测指定进程的CPU及物理内存消耗情况(c程序)
- Blazor带我重玩前端(二)
- axios 使用步骤很简单,首先在前端项目中,引入 axios:
- jqgrid 编辑列拿不到值_如何在DAX Stadio和Excel中返回表和度量值?
- MFC开发IM-第四篇、mfc 对话框dialog的属性意思
- Laravel 5无法打开所需的bootstrap /../ vendor / autoload.php
- python报告,python测试结果报告
- 日记侠:微信传说的功能升级了,你用了没有?
- 132 个 Web 设计工具(上)
- 【WebApp】离线webapp (iPad版本)开发手记
- 【华人学者风采】陈积明 浙江大学
- 【算法】Shannon Entropy决策中的香农熵介绍、计算以及python代码实现
- 2020年3月中国编程语言排行榜
- 详述图片base64加密的原理,告诉你什么是“/9j/“
- mysql 一 、关系模型——主键——外键——索引
- idea更改MySQL依赖版本时错误:Duplicated tag: ‘properties‘ (position: START_TAG seen ...
- js 日期判断是否是今天
- week67(2021.10.23-2021.11.5)
热门文章
- 解决双网卡外网、内网冲突问题
- 荆小花推荐伤感非主流日志:一次想你,都感觉心痛!
- uploadify使用详解
- catia圆型与矩形的桥接_4.3.7.2-桥接曲面_复杂构面
- Kotlin Delegated Properties
- 华中科技大学计算机专业导师,华中科技大学通信与信息系统专业导师介绍:屈代明...
- oracle监控插件
- Android studio获取服务器端json数据——天气预报(仅读取了json文件尚未分析)
- 诚邀各界人士共赏--2011年百度运维部迎新生晚会
- python自动化运维学习笔记汇总