题解 | #表示数字#
表示数字
https://www.nowcoder.com/practice/637062df51674de8ba464e792d1a0ac6
#include <cctype> #include <iostream> #include <list> using namespace std; struct ListNode { char val; ListNode* next; ListNode(): val('0'), next(nullptr) {} ListNode(char data): val(data), next(nullptr) {} ListNode(char data, ListNode* node): val(data), next(node) {} }; int main() { ListNode* pre = new ListNode(); char ch; auto* cur = pre; while (cin >> ch) { ListNode* node = new ListNode(ch); cur->next = node; cur = cur->next; } cur = pre; while (cur) { if (cur->next && isdigit(cur->next->val)) { ListNode* newNode = new ListNode('*'); newNode->next = cur->next; cur->next = newNode; cur = cur->next; while (cur->next) { if (!isdigit(cur->next->val)) { ListNode* node2 = new ListNode('*'); node2->next = cur->next; cur->next = node2; break; } cur = cur->next; } if (!cur->next) { ListNode* node2 = new ListNode('*'); node2->next = cur->next; cur->next = node2; } } cur=cur->next; } cur=pre->next; while(cur){ cout<<cur->val; cur=cur->next; } return 0; } // 64 位输出请用 printf("%lld")