C++
三水有余
SCNUCS
展开
-
C++的动态类型:variant搭配visit与any
C++的动态类型:variant搭配visit与any最近在写一个程序,里面用到一个数据结构,类似于字典,但一个实例里面,不同key对应的值的类型可能不一样。例如key为{年龄,性别}。这就要求我们在声明映射map时提供的模板参数能满足不同的数据类型,目前在不改变数据结构的情况下想到的解决方案有两种:使用variant或者any。variantvariant是C++17标准的新特性。用法variant<int, bool, string> var;// 声明一个可以接受int、bool原创 2021-06-21 00:20:37 · 920 阅读 · 0 评论 -
PAT Advanced Level 1002 A+B for Polynomials
PAT Advanced Level 1002 A+B for Polynomials题目This time, you are supposed to find A+B where A and B are two polynomials.Input Specification:Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a p原创 2020-12-30 09:51:24 · 175 阅读 · 0 评论 -
PAT Advanced Level 1001 A+B Format
PAT Advanced Level 1001 A+B Format1001 A+B Format题目原文分析AC代码1001 A+B Format题目原文1001 A+B Format (20分)Calculate a+b and output the sum in standard format – that is, the digits must be separated into groups of three by commas (unless there are less than fo原创 2020-12-30 09:23:29 · 120 阅读 · 0 评论