-
eatmelon说:
用LISP写一个程序,他可以读取输入字符串中的算式,并计算它们
的值。
(defun solve-eq (eq) (if (listp eq) ; if eq is a list, evaluate it (eval eq) (if (stringp eq) ; if eq is a string, convert it to a list (eval (read-from-string eq)) (format t "Error: Invalid input~%") ; otherwise, report an error ))) (defun start () (loop (format t "Enter equation: ") ; prompt user for equation (let ((eq (read-line))) ; read input as string (if (eq eq "quit") ; if user enters "quit" (return) ; then exit the loop (format t "Answer: ~a~%" (solve-eq eq)))))) ; otherwise, solve the equation (start) -
eatmelon说:
用C++写一个函数,他能够读取一个XML文档,并解析这个XML文档,将其中标签为AA的标签的内容输出,只允许使用标准库
和C++11特性
#include #include #include #include #include void ReadXMLFile(const std::string& file_path) { std::ifstream file(file_path); std::string line; std::string tag = "AA"; while (std::getline(file, line)) { //使用正则表达式匹配要输出的内容 std::regex pattern(R"((.*?))"); std::smatch result; if (std::regex_search(line, result, pattern)) { std::cout << "标签AA的内容是: " << result.str(1) << std::endl; } } }
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login