日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2025/3/8 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 “玲珑杯”线上赛 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

總結

以上是生活随笔為你收集整理的“玲珑杯”线上赛 Round #15 河南专场 F咸鱼文章的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。