当前位置:网站首页>乐山师范程序设计大赛2020-D: 后缀语言【STL】
乐山师范程序设计大赛2020-D: 后缀语言【STL】
2022-07-19 05:15:00 【星空皓月】
题目描述
在自然语言处理中,后缀是一种常见的形式。
给定三种不同的语言和三个不同的后缀,可以用后缀确定句子是用的哪一种语言。这个方法非常简单和准确,并且不涉及任何高级的机器学习算法。
它的逻辑如下:
如果句子以 “po” 结尾,那么它就是菲律宾语 (Filipino);
如果句子以 “desu” 或 “masu” 结尾,那么它就是日语 (Japanese);
如果句子以 “mnida” 结尾,则是韩语 (Korea)。
以此我们可以通过后缀来区分菲律宾语、日语和韩语。
输入
输入包括多组数据;
第一行只有一个整数 t (1 ≤ t ≤ 30) 表示输入数据的组数;
接下来输入 t 行,每行是一个句子(只包含下划线和小写字母),每个句子长度不超过1000个字符,且必定以上述后缀结束。
输出
对于每组数据,输出对应的语言(全大写,没有引号),
若是菲律宾语输出 “FILIPINO”;
若是日语输出 “JAPANESE”;
若是韩语输出 “KOREAN”。
样例输入
8
kamusta_po
genki_desu
ohayou_gozaimasu
annyeong_hashimnida
hajime_no_ippo
bensamu_no_sentou_houhou_ga_okama_kenpo
ang_halaman_doon_ay_sarisari_singkamasu
si_roy_mustang_ay_namamasu
样例输出
FILIPINO
JAPANESE
JAPANESE
KOREAN
FILIPINO
FILIPINO
JAPANESE
JAPANESE
思路
直接调用string中的substr(st, len)函数,st代表起始位置,len是截取长度。
坑点:需要判一下字符串的长度(例如:po)。不然substr要抛异常。
这个题还有更简便的方法,我们观察题目的要求,输出必定对应一种语言,而且三种语言的最后一个字母不相同,就可以根据最后一个字母来判定。
AC代码
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
typedef long long ll;
void solve() {
string s;
cin >> s;
int len = s.size();
string s1 = s.substr(len - 2, 2);
string s3 = "", s2 = "";
if (len >= 4) {
s2 = s.substr(len - 4, 4);
}
if (len >= 5) {
s3 = s.substr(len - 5, 5);
}
if (s1 == "po") {
puts("FILIPINO");
} else if (s2 == "desu" || s2 == "masu"){
puts("JAPANESE");
} else if (s3 == "mnida"){
puts("KOREAN");
}
}
int main() {
int t;
cin >> t;
for (int i = 0; i < t; ++i) {
solve();
}
return 0;
}
边栏推荐
- RS232标准DB9接口定义
- G2l series core board -rz/g2l processor introduction | frame diagram | power consumption | schematic diagram and hardware design guide
- Default password of common devices
- Vulnhub target earth
- FreeRTOS thread safe and interrupt safe printf implementation
- Solution of STM32 cubeide breakpoint failure
- C language data type and uint8 under typedef_ t / uint32_ t
- Secure Code Warrlor学习记录(二)
- (data and electricity) summary of various triggers - FPGA octet (1)
- Leetcode:20. 有效的括号【三种思路+不同语言实现】
猜你喜欢
Detailed explanation of tunnel and agent usage in SSH protocol
PCB在导出gerber文件时过孔盖油设置方法
The end result of printf - where is the data printed
Program verification of one-dimensional wavelet transform based on cyclic convolution (C language)
RS232 standard DB9 interface definition
Solution to the problem of constantly popping up blank web pages when opening OrCAD capture CIS in cadence 17.2
Quanzhi t507 removes the IO expansion chip and retains the expansion pin function
FPGA network port implementation and detailed explanation (2)
Vivado2018.2 version with PS side configuration (BD) when calling Modelsim simulation: (vlog-13006) could not find the package (sc_util_v1_0_3_pkg)
代码审计之企业级进销存管理系统
随机推荐
【BOM】初识BOM~
如何把一个“平台” 塞进一个小盒子里?(下)|技术实现篇
Bing Bing search doesn't work
Redux main knowledge learning summary
Infrared decoding program based on timer capture function (NEC protocol)
Precautions for the selection and conversion of single power supply operational amplifier and dual power supply operational amplifier and their power supply mode
The Debian system is ported with USBWiFi rtl8192eu driver and set to start automatically
计算机408+数据库【适合考研复试或期末复习】
vulnhub 靶机 Earth
Secure Code Warrlor学习记录(二)
解决问题phpstudy导入数据库失败
Verilog HDL language summary (full)
FPGA majority voter (including code)
2022-7-12 第八小组 顾宇佳 (Js)
Automatic nucleic acid extraction instrument based on ARM core board
单电源运放和双电源运放及其供电方式选择与转换的注意事项
Xilinx 7系列原语使用(时钟相关)——(一)
Redux 主要知识学习总结
Output PWM square wave with ls1028a development board
Experience of installing ROS in Jetson nano (failed)