#include <bits/stdc++.h>
using namespace std;
struct ListNode {
int val;
ListNode *next;
ListNode() : val(INT_MIN), next(nullptr) {} // 构造函数
ListNode(int _val) : val(_val), next(nullptr) {} // 构造函数
};
ListNode* reverseList(ListNode* head) {
ListNode *pre = nullptr, *cur = head; // pre指向前一个节点,cur指向当前节点
while (cur) { // 遍历链表
ListNode *tmp = cur->next; // 保存当前节点的下一个节点
cur->next = pre; // 将当前节点的next指针指向前一个节点
pre = cur; // 将当前节点赋值给前一个节点
cur = tmp; // 将当前节点指向下一个节点
}
return pre; // 返回反转后的链表
}
ListNode *buildList(vector<int> &nums) { // 建立链表
ListNode *head = new ListNode(); // 头节点
ListNode *cur = head; // cur 指向当前节点
for (int i = 0; i < int(nums.size()); i++) { // 遍历数组
cur->next = new ListNode(nums[i]); // 将数组元素插入链表
cur = cur->next; // 将当前节点指向下一个节点
}
return head->next; // 返回链表
}
void outputList(ListNode *head) { // 输出链表
ListNode *cur = head; // cur 指向当前节点
while (cur) { // 遍历链表
cout << cur->val << " "; // 输出当前节点的值
cur = cur->next; // 将当前节点指向下一个节点
}
cout << endl;
}
int main() {
int num;
vector<int> nums;
while (cin >> num) {
nums.push_back(num);
if (cin.get() == '\n') break;
}
ListNode *head = buildList(nums);
ListNode *res = reverseList(head);
outputList(res);
return 0;
}