“玲瓏杯”線上賽 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.pswp.cn/news/541287.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/541287.shtml
英文地址,請注明出處:http://en.pswp.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…