当前位置:网站首页>Niuke.com string deformation
Niuke.com string deformation
2022-06-24 09:16:00 【SZU healing system bug】
Catalog
Title Description
For a length of n character string , We need to deform it .
First of all, the string contains some spaces , It's like "Hello World" equally , Then what we need to do is reverse order the words separated by spaces in this string , Invert the case of each character at the same time .
such as "Hello World" After deformation, it becomes "wORLD hELLO".
Data range : 1\le n \le 10^61≤n≤106 , The string contains uppercase English letters 、 Small letters 、 Space .
Advanced : Spatial complexity O(n)O(n) , Time complexity O(n)O(n)
Input description :
Given a string s And its length n(1 ≤ n ≤ 10^6)
Return value description :
Please return the deformed string . The title ensures that the given string is composed of upper and lower case letters and spaces .
Thought analysis
See clearly that the title says to reverse the order of the words .
My thinking is more popular , To reverse the order of words , First, reverse the character order of the entire string , then , Use the space as the judgment point for dividing words in the string , Separate each part by a space ( The word ) Reverse again .
For convenience , I call library functions as much as I can .
AC Code
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
string s;
int n,i,j;
getline(cin,s);
cin>>n;
for(auto& element:s){
if(isupper(element))
element+=32;
else if(islower(element))
element-=32;
}
reverse(s.begin(),s.end());
for(i=0;i<n;i++){
for(j=i;j<n;j++)
if(s[j]==' ')
break;
reverse(s.begin()+i,s.begin()+j);
i=j;
}
cout<<s;
}边栏推荐
- 2022.06.23 (traversal of lc_144,94145\
- Installation of sophus package in slam14 lecture
- Implementation process of tcpdump packet capturing
- Opencv maximum filtering (not limited to images)
- Project deployment related
- Time Series Data Augmentation for Deep Learning: A Survey 之论文阅读
- 1528. rearrange strings
- 【LeetCode】415. String addition
- Depens:*** but it is not going to be installed
- PM2 deploy nuxt3 JS project
猜你喜欢

Squid代理服务器应用

Huawei Router: IPSec Technology

关于 GIN 的路由树

Lu Qi: I am most optimistic about these four major technology trends

十二、所有功能实现效果演示

Rpiplay implementation of raspberry pie airplay projector

深入了解 border

Spark - LeftOuterJoin 结果条数与左表条数不一致

Spark - the number of leftouterjoin results is inconsistent with that of the left table

零基础自学SQL课程 | HAVING子句
随机推荐
Support vector machine (SVC, nusvc, linearsvc)
pm2 部署 nuxt3.js 项目
Zero foundation self-study SQL course | having clause
软件系统依赖关系分析
When programmers are asked if they can repair computers... | daily anecdotes
520. detect capital letters
MYCAT read / write separation and MySQL master-slave synchronization
Spark - LeftOuterJoin 结果条数与左表条数不一致
Go 语言项目开发实战目录
Epidemic situation, unemployment, 2022, we shouted to lie down!
Idea another line shortcut
从618看京东即时零售的野心
eBanb B1手环刷固件异常中断处理
Recommendation - Secret of curiosity: how many dancing angels can stand on the tip of a needle?
On the routing tree of gin
十二、所有功能实现效果演示
Weekly recommended short video: is the ultimate form of computing "meta universe"?
MySQL data (Linux Environment) scheduled backup
Linux (centos7.9) installation and deployment of MySQL Cluster 7.6
linux(centos7.9)安装部署mysql-cluster 7.6