c/c++语言开发共享[2020牛客暑期多校训练营第三场] L.Problem L is the Only Lovely Problem 字符串函数

题目链接:L.Problem L is the Only Lovely Problem前言:一般是不写签到题的,但这次例外,原因是我牛客比赛第一次一眼瞄到了签到题,但却由于字符串的一些函数忘了导致没能很快地切出这个签到题。属实很难受,但这也反映了我对c++函数使用并不熟练,以后有关函数使用的我会单独开个模块,遇到了写一篇,以便赛前温习用。题意:给你一个字符串,判断前6个字母是否为”lovely”,不区分大小写。是输出”lovely”,否输出”ugly”。题解:本题若想快速求解,用c++自带的转变小写函


题目链接:L.Problem L is the Only Lovely Problem

前言:一般是不写签到题的,但这次例外,原因是我牛客比赛第一次一眼瞄到了签到题,但却由于字符串的一些函数忘了导致没能很快地切出这个签到题。属实很难受,但这也反映了我对c++函数使用并不熟练,以后有关函数使用的我会单独开个模块,遇到了写一篇,以便赛前温习用。

题意:给你一个字符串,判断前6个字母是否为”lovely”,不区分大小写。是输出”lovely”,否输出”ugly”。

题解:本题若想快速求解,用c++自带的转变小写函数tolower()和字符串截取函数substr(),会提高速度。

tolower(char c),将字符c转变小写,不能将整个字符串放进参数里。
substr(int l,int r) 截取字符串[l,r)长度为(r-l)子字符串

代码

#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<bitset> #include<cassert> #include<cctype> #include<cmath> #include<cstdlib> #include<ctime> #include<deque> #include<iomanip> #include<list> #include<map> #include<queue> #include<set> #include<stack> #include<vector> using namespace std; typedef long long ll; typedef long double ld; #define fi first #define se second #define pb push_back #define mp make_pair #define pii pair<int,int>  const double PI=acos(-1.0); const double eps=1e-6; const ll mod=1e9+7; const int inf=0x3f3f3f3f; const int maxn=1e5+10; const int maxm=100+10; #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);  int main() { 	string s; 	cin >> s; 	for(int i=0;i<s.length();i++) 		s[i]=tolower(s[i]); 	if(s.substr(0,6)=="lovely") 		cout << "lovely" << endl; 	else cout << "ugly" << endl; } 

c/c++开发分享[2020牛客暑期多校训练营第三场] L.Problem L is the Only Lovely Problem 字符串函数地址:https://blog.csdn.net/weixin_44235989/article/details/107443706

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/c-cdevelopment/598553.html

(0)
上一篇 2021年5月8日
下一篇 2021年5月8日

精彩推荐