字符串操作,起点初始位置是0,从起点开始往后找到第一个标识符的位置,也就是终点。若终点存在,则从终点往后到起点输出字符串,将起点向前移动到终点的前一位,继续上述操作;若终点不存在(即没有标识符了),那么终点就是字符串的最后一位,仍然倒序输出,输出后结束。
Run Time: 0sec
Run Memory: 312KB
Code length: 595Bytes
Submit Time: 2012-01-12 01:50:02
// Problem#: 2038
// Submission#: 1188605
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <iostream>
#include <string>
using namespace std;
int main()
{
int m;
int i, start, end;
string s;
cin >> m;
while ( m-- ) {
cin >> s;
start = 0;
end = s.find_first_of( '_', start );
while ( end != string::npos ) {
for ( i = end - 1; i >= start; i-- )
cout << s[ i ];
cout << '_';
start = end + 1;
end = s.find_first_of( '_', start );
}
for ( i = s.size() - 1; i >= start; i-- )
cout << s[ i ];
cout << endl;
}
return 0;
}
本文介绍了一种从字符串中定位标识符并进行特定操作的方法,包括从定位点倒序输出字符直至起始点,然后将起始点向前移至定位点前一位,重复此过程直至字符串结束。
640

被折叠的 条评论
为什么被折叠?



