山東省第七屆ACM大學生程式設計競賽-Reversed Words
Reversed Words
Time Limit: 2000ms Memory limit: 131072K 有疑問?點這裡^_^
題目描述
Some aliens are learning English. They have a very strange way in writing that they revered every word in the sentence but keep all the words in common order. For example when they want to write “one two three”, they will write down “eno owt eerht”.
Now we’ve got some sentence written by these aliens, translate them! And maybe we will know some of their secrets!
輸入
Multiple test cases. The first line contains a positive integer T (T <= 1000), indicating the number of test cases.
For each test cases, there will be one line contains only lower case letters and spaces. The length of each line will be no more than 10000. Test cases which are longer than 5000 will be less than 50. Continuous letters are seen as a word, words are separated by spaces. There won’t be two adjacent spaces in the input. Space won’t be the first or the last character.
輸出
One line per case, the translated sentence.
示例輸入
2
eno owt eerht
abcde
示例輸出
one two three
edcba
提示
來源
“浪潮杯”山東省第七屆ACM大學生程式設計競賽
字串反轉……本來沒什麼好說的……但是!!!
習慣了用C++,然後gets或者cin.getline一行,這樣就出問題了……
用控制檯還看不出來,交了就WA。加了freopen才發現out其實全是空白行。
原因阿,就是cin>>t的後面有個回車符,要把它吃掉,不然就被gets讀到了,下面的字串就讀不到了……
簡直神坑……比賽的時候因為gets坑了兩道題除了這個還有那道爐石水模擬……不說了都是淚……
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
#define MAXN 10001
int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("G:/x/read.txt","r",stdin);
freopen("G:/x/out.txt","w",stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin>>t;
char a[MAXN];
cin.getline(a,MAXN);//吃掉回車
while(t--)
{
cin.getline(a,MAXN);//讀入一行
int i,j,k=-1;
int len=strlen(a);
for(i=0; i<=len; ++i)
{
if(a[i]==' ')
{
for(j=i-1; j>=k+1; --j)
cout<<a[j];
cout<<" ";
k=i;
}
if(i==len)
for(j=len-1; j>=k+1; --j)
cout<<a[j];
}
cout<<endl;
}
return 0;
}
/*
2
eno owt eerht
abcde
*/
相關文章
- 第八屆山東省ACM大學生程式設計競賽總結ACM程式設計
- 山東省第一屆ACM大學生程式設計競賽-Balloons(搜尋)ACM程式設計
- 山東省第六屆ACM大學生程式設計競賽-Square Number(完全平方數)ACM程式設計
- 山東省第六屆ACM大學生程式設計競賽-Lowest Unique Price(桶排序)ACM程式設計排序
- 山東省第四屆ACM大學生程式設計競賽-Rescue The Princess(計算幾何)ACM程式設計
- 山東省第四屆ACM大學生程式設計競賽-Contest Print Server(模擬)ACM程式設計Server
- 山東省第六屆ACM大學生程式設計競賽-Single Round Math(大數除法)ACM程式設計
- 2012年"浪潮杯"山東省第三屆ACM大學生程式設計競賽(熱身賽)ACM程式設計
- 山東省第四屆ACM大學生程式設計競賽-Alice and Bob(二進位制&&找規律)ACM程式設計
- 山東省第四屆ACM大學生程式設計競賽-Boring Counting(劃分樹-二分查詢)ACM程式設計
- 山東省第八屆 ACM 省賽 quadratic equation (水、坑)ACM
- 山東省第五屆ACM大學生程式設計競賽-Full Binary Tree(二叉樹&&求任意兩節點路徑)ACM程式設計二叉樹
- 山東省第五屆ACM大學生程式設計競賽-Hearthstone II(組合數學-第二類Stirling數)ACM程式設計
- 第15屆浙江省大學生程式設計競賽D題程式設計
- 山東省第四屆acm解題報告(部分)ACM
- 我校學子在山東省ACM競賽中獲得優異成績ACM
- 湖南省大學生程式設計競賽系統設計程式設計
- 2019山東ACM省賽補題題解ACM
- [題解][2021-2022年度國際大學生程式設計競賽第10屆陝西省程式設計競賽] Type The Strings程式設計
- 無錫學院2024年ACM大學生程式設計競賽校選賽 題解ACM程式設計
- [補題] 第 45 屆國際大學生程式設計競賽(ICPC)亞洲區域賽(上海)程式設計
- 2014年藍橋杯程式設計大賽山東省賽區成績公佈程式設計
- 第43屆ACM-ICPC國際大學生程式設計競賽 亞洲區域賽南京站現場賽名額分配相關說明ACM程式設計
- 2020 年第一屆遼寧省大學生程式設計競賽 D.開心消消樂(點分治)程式設計
- ACM-ICPC世界冠軍教你如何備戰程式設計競賽ACM程式設計
- QZEZ第一屆“飯吉圓”杯程式設計競賽程式設計
- 藍橋杯__省賽__第七屆__C/C++__大學A組C++
- 華中農業大學第十三屆程式設計競賽程式設計
- 北京資訊科技大學第十一屆程式設計競賽(重現賽)I程式設計
- 大學生電子設計競賽電源資料
- 第十七屆中國計量大學程式設計競賽 I- Isolated Pointset程式設計
- 某大學程式設計競賽程式設計
- 華中農業大學第十三屆程式設計競賽 題解程式設計
- 第七屆藍橋杯大賽個人賽省賽(軟體類)真題 C語言A組 1C語言
- 2017第二屆廣東省強網杯線上賽- who are you
- 第二屆“演算法控”馬拉松程式設計競賽 解題思路演算法程式設計
- 牛客競賽,GDDU第十屆文遠知行杯新生程式設計競賽,摸魚記(BDEIKL題解,補G,ACFHJ)程式設計
- 第十五屆全國大學生智慧車安徽賽區參賽須知和競賽日程安排