因为缺少对输入字符串的合法性检查,如果输入的字符串中存在不在文法符号集中的字符,会导致程序在查找对应的映射时出现错误。可以在程序开始处加入以下代码进行检查:

for (char c : input) { if (vt.find(c) == vt.end()) { cout << "Invalid input!" << endl; return 0; } }

#include iostream#include map#include vector#include stackusing namespace std;mapchar int vt = + 0 - 1 2 3 4 5 6 7 8 f 9 x 10;mapint char rv = 0 + 1 - 2 3 4 5 6 7 8 9 f 10 x;vectorvector

原文地址: http://www.cveoy.top/t/topic/huED 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录