HD-ACM算法专攻系列(7)——Text Reverse
问题描述:
源码:
/**/ #include"iostream" #include"string" using namespace std; void Print(string str, int end, int start) { for(int i = end; i >= start; i--)cout<<str[i]; } int main() { int n, start, end; string str; while(cin>>n) { getchar(); for(int i = 0; i < n; i++) { getline(cin, str); start = end = 0; for(int j = 0; j < str.length(); j++) { if(str[j] == ' ') { end = j - 1; if(start != 0)cout<<" "; Print(str, end , start); start = j + 1; } } if(start != 0)cout<<" "; Print(str, str.length() - 1, start); cout<<endl; } } return 0; }