[2020牛客暑期多校训练营第三场] L.Problem L is the Only Lovely Problem 字符串函数

2 篇文章 0 订阅
题目链接: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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值