ZOJ 1151——Word Reversal
生活随笔
收集整理的這篇文章主要介紹了
ZOJ 1151——Word Reversal
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
有是一個字符串翻轉問題,唉,自以為處理的很巧妙,因為如果整句輸入可能真的不好處理,呵呵,反正沒這樣簡單!code:#include <cstring>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
int t,j=1;
char k;
cin >> t;
getchar();
while (1) {
if (j > t)
break;
string p;
cin >> p;
reverse(p.begin(), p.end()); //hehe,輸入一個轉換一個
cout << p;
k = getchar();
if (k ==' ')
cout <<" ";
if (k == '\n') { //有換行我就處理下一行
j++;
cout << endl;
}
}
if (n)
cout << endl;
}
}
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
int t,j=1;
char k;
cin >> t;
getchar();
while (1) {
if (j > t)
break;
string p;
cin >> p;
reverse(p.begin(), p.end()); //hehe,輸入一個轉換一個
cout << p;
k = getchar();
if (k ==' ')
cout <<" ";
if (k == '\n') { //有換行我就處理下一行
j++;
cout << endl;
}
}
if (n)
cout << endl;
}
}
總結
以上是生活随笔為你收集整理的ZOJ 1151——Word Reversal的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 成都大熊猫繁育研究基地什么时候免费
- 下一篇: 老马家的幸福往事剧情介绍