“玲珑杯”线上赛 Round #15 河南专场 F 咸鱼文章

elttiL moT nwod eht teerts sllac ruo god ” ehT peek god ” . piZ si a peehs god . tuB nehw moT seirt ot yas ” peeS ” , ti semoc tuo ” peek ” . dnA ni a yaw moT si thgir . piZ si syawla gnignirb sgniht oh rof su ot peek ! ll’I llet uoy tuoba emos fo meht .
s’piZ tsrif tneserp saw a eohs . tI saw edam fo neerg klis .
eW t’ndid wonk woh piZ dnuof eht eohs . tuB retfa a tnemom yraM , ym gib retsis , dlot em eht eohs dah a egnarts llems . I deddon dna dleh ym eson . ” tahW od uoy kniht ti si ? ”
” tI sllems ekil gnihtemos rof gninaelc . I kniht enoemos deirt ot naelc a tops ffo eht eohs . nehT eh tup ti ta eht rood ot yrd . ”
” gnolA emac piZ . dnA eyb-doog eohs ! ” I dias . ” eW dluohs ekat ti kcab . ”
” eW t’nac ” . dias ym rettsis .
” ebyaM elttil moT si thgir , ” yraM dias . ” ebyaM piZ si a peek god ! “

你正在做英语阅读,可哪知这是一篇咸鱼文章,整个文章的所有单词都是翻转的,你很慌。

不过你是咸鱼程序员,你可以写代码将这篇文章翻转回来,那么翻转回来吧。

INPUT
输入一篇英文文章。

输入数据中只包含空格、换行符和小写大写字母。

满足总字数小于等于100000
OUTPUT
你应该把这个文章的所有单词都翻转回来,输出即可。
SAMPLE INPUT
AAA BBB
AB AB
SAMPLE OUTPUT
AAA BBB
BA BA
sb题搞死我,气死我啦!!!
刚开始在想空格与换行的区分(其实不用区分),想它们的码值。
后来看来题解之后
题解是这样的:F 咸鱼文章

用栈来做这道题,遇到字母,我们就扔到栈里面去,遇到空格或者换行的时候,我们就把栈里面的元素输出,然后再输出空格/换行就好了。
然后我就超时了,超时代码附上

//超时代码,两层for,gg
#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<stack>
#include<iostream>
#include<algorithm>
using namespace std;
const int inf=0x3f3f3f3f;
char str[10000][10000];
int main()
{int len=0;memset(str,0,sizeof(str));while(gets(str[len++])){if(str[len-1][0]==0)break;}for(int i=0;i<len-1;i++){stack<char>q;int p=strlen(str[i]);for(int j=0;j<=p;j++){//printf("%d ",j);if((str[i][j]>='a'&&str[i][j]<='z')||(str[i][j]>='A'&&str[i][j]<='Z')){q.push(str[i][j]);}else{while(!q.empty()){printf("%c",q.top());q.pop();}printf(" ");}}printf("\n");}return 0;
}

大概看了别人代码后,又想怎么结束输入(不用想,Ctrl+z,结束输入,水题刷的不够啊!)
然后粘正确代码

#include<cstdio>
#include<cstring>
#include<stack>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
char a[100005];
char b[100005];
int main()
{int perlen=0;while(gets(a)){int p=0;int len=strlen(a);//长度正好包含最后一个字母,没有'\n'for(int i=perlen; i<perlen+len; i++)b[i]=a[p++];b[perlen+len]='\n';perlen=perlen+len+1;}stack<char>q;for(int i=0; i<perlen; i++){if((b[i]>='a'&&b[i]<='z')||(b[i]>='A'&&b[i]<='Z'))q.push(b[i]);else{while(!q.empty()){printf("%c",q.top());q.pop();}printf("%c",b[i]);}}return 0;
}

1.不用考虑输入终止
2.学习这种记录空格与换行
3.strlen()的长度是到最后一个字母的长度,没有’\n’

转载于:https://www.cnblogs.com/zxy160/p/7215099.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/541287.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

线性代数向量内积_向量的外积| 使用Python的线性代数

线性代数向量内积Prerequisites: 先决条件&#xff1a; Defining Vector using Numpy 使用Numpy定义向量 Learn: how to code for outer product of two vectors using am inbuilt function in numpy library? 了解&#xff1a;如何使用numpy库中的内置函数为两个向量的外部乘…

c语言案例朗读工具源码,C语言编写简单朗读小工具(有源码)

原标题&#xff1a;C语言编写简单朗读小工具(有源码)最近不少人在后台留言说学C都是面对枯燥的控制台程序&#xff0c;能不能体现一下C语言的实际用途&#xff0c;今天我们就理论结合实践一把&#xff1a;C语言结合VBS脚本编写一个简单的朗读小工具&#xff0c;做一个能够发音的…

WAS集群系列(5):集群搭建:步骤3:安装IHS软件

选择“安装IBM HTTPServer”选项&#xff0c;点击“安装向导”。例如以下图提示&#xff1a; 安装提示&#xff0c;逐步点击“下一步”&#xff0c;当中偶有几处细节注意就可以。列举例如以下&#xff1a; &#xff08;1&#xff09;、产品安装路径与先前WAS软件所安装路径统一…

L1-056 猜数字 C语言,PAT L1-032 Left-pad

根据新浪微博上的消息&#xff0c;有一位开发者不满NPM(Node Package Manager)的做法&#xff0c;收回了自己的开源代码&#xff0c;其中包括一个叫left-pad的模块&#xff0c;就是这个模块把javascript里面的React/Babel干瘫痪了。这是个什么样的模块&#xff1f;就是在字符串…

单链表删除整表_单链表删除

单链表删除整表Deletion can be at various positions like: 删除可以在各个位置进行&#xff0c;例如&#xff1a; Deleting the first node 删除第一个节点 Deleting the last node 删除最后一个节点 Deleting the intermediate node 删除中间节点 删除单个链表中的第一个节…

WordPress数据表wp-options数据字段存JSON数据

2019独角兽企业重金招聘Python工程师标准>>> wp_options表是WordPress中最重要的表&#xff0c;一切程序设置、主题设置和绝大多数插件的设置大都保存在此表。 WordPress里面数据表wp-options数据字段存JSON数据 &#xff1a; a:90: {s:11:"^wp-json/?$"…

css scroll属性_CSS中的scroll-behavior属性

css scroll属性CSS | 滚动行为属性 (CSS | scroll-behavior property) Who does not want their links to function smoothly and attractively? This type of functionality is very easy to implement. All you need is a bit of awareness about the property that would h…

c 语言五子棋游戏代码,C语言案例:控制台版本的五子棋游戏【代码】

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼return true;}x;}return false;}bool isLeftInclinedWin(bool isBlack,int x,int y){char c isBlack ? :O;int count;while(x>0 && y>0 && state[x][y] c){y--;x--;}count 0;if(state[x][y] c) count 1…

基于HTML5 Canvas 实现弹出框

用户鼠标移入时&#xff0c;有弹出框出现&#xff0c;这样的需求很常见。这在处理HTML元素实现时简单&#xff0c;但是如果是对 HTML5 Canvas 构成的图形进行处理&#xff0c;这种方法不再适用&#xff0c;因为 Canvas 使用的是另外一套机制&#xff0c;无论在 Canvas 上绘制多…

半素数c语言,非常简单的c题目 不懂 紧急求助

1 半素数素数是指大于1且只有1和他本身两个因子的正整数&#xff0c;例如2、3、5、89都是素数&#xff0c;2、4、10都不是素数。在这里我给半素数下一个定义&#xff1a;一个大于1的正整数能分解为两个素数的乘积&#xff0c;那么这个正整数就是半素数&#xff0c;比如62*3&am…

JavaScript | 嵌套if的示例

Example: 例&#xff1a; In this example, we are reading salary of an employee and finding the discount and net pay based on given salary and discount rate. 在此示例中&#xff0c;我们正在读取员工的薪水&#xff0c;并根据给定的薪水和折扣率找到折扣和净工资。 …

POJ 1014 Dividing 背包

二进制优化&#xff0c;事实上是物体的分解问题。 就是比方一个物体有数量限制&#xff0c;比方是13&#xff0c;那么就须要把这个物体分解为1。 2&#xff0c; 4&#xff0c; 6 假设这个物体有数量为25&#xff0c;那么就分解为1&#xff0c; 2&#xff0c; 4。 8。 10 看出规…

node.js 中间件_Node.js中的Passport中间件(模块)

node.js 中间件Hi! Welcome to Node.js Authentication Series, where well study and program the passport module or middleware. 嗨&#xff01; 欢迎使用Node.js身份验证系列 &#xff0c;我们将在其中研究和编程通行证模块或中间件 。 Nowadays, an important tool in m…

android开发自动提示框,Android 多种简单的弹出框样式设置代码

简介这是一个基于AlertDialog和Dialog这两个类封装的多种弹出框样式&#xff0c;其中提供各种简单样式的弹出框使用说明。同时也可自定义弹出框。项目地址&#xff1a;http://www.easck.com/jjdxmashl/jjdxm_dialogui特性1.使用链式开发代码简洁明了2.所有的弹出框样式都在Dial…

小程序中利用Moment.js格式时间

2019独角兽企业重金招聘Python工程师标准>>> LeanCloud给的日期是ISO格式&#xff0c;比如2017-06-05T14:08:20.589Z&#xff0c;直接显示在页面上体验不好。 凡是有关日期的&#xff0c;格式化、计算&#xff0c;用moment就够了。 1.下载 http://momentjs.com/ 选m…

php 检查数组为空_检查数组是否为空在PHP中

php 检查数组为空Given an array and we have to check if array is an empty or not using PHP. 给定一个数组&#xff0c;我们必须检查数组是否为空或不使用PHP。 To check whether an array is empty or not, we can use a built-in function empty(), in other cases wher…

JEESZ分布式架构3--CentOs下安装MySQL(环境准备)

声明&#xff1a;因为运行环境是基于Linux系统的&#xff0c;在做此框架之前需要做一些前期的环境准备工作CentOs下安装MySQL网上很多实例&#xff0c;因为博客后期作为框架的原生教程&#xff0c;故这边做详细的安装记录&#xff0c;我这边已经下载好了MySQL&#xff0c;通过s…

一个函数里两个setjmp_C语言中setjmp.h的longjmp()函数

一个函数里两个setjmpWe can call this function as an advance version of goto statement but with more dynamic range. The longjump() function allows us to pass parameters to know that the control has been jumped or not. 我们可以将此函数称为goto语句的高级版本&…

linux sublime nodejs,Ubuntu环境下sublime3 nodejs安装与插件配置

1.sudo add-apt-repository ppa:webupd8team/sublime-text-3回车&#xff0c;出现很多信息。但是我们看看图片最后字知道&#xff0c;这地方在等待我们确认是否添加这个仓库&#xff0c;按enter键继续&#xff0c;按crtlc取消。此时&#xff0c;按ENTER继续&#xff0c;建立信任…

李洪强iOS开发之FMDB线程安全的用法

// // ViewController.m // 04 - FMDB线程安全的用法 // // Created by 李洪强 on 2017/6/6. // Copyright © 2017年 李洪强. All rights reserved. // #import "ViewController.h" //导入头文件 #import "FMDB.h" interface ViewController () p…