电话号码身份

来源:互联网 发布:网络舆情的重要性 编辑:程序博客网 时间:2024/04/28 20:20

这里写图片描述
这里写图片描述
C++代码实现:

#include <iostream>#include <string>#include <algorithm>#include <vector>#include <map>using namespace std;int main(){    map<string, string> mp;    map<string, string>::iterator it;    const char *sChar = NULL;    string s;    const char *p = sChar;    vector<int> v;    int line;    mp["ZERO"] = "2";    mp["ONE"] = "3";    mp["TWO"] = "4";    mp["THREE"] = "5";    mp["FOUR"] = "6";    mp["FIVE"] = "7";    mp["SIX"] = "8";    mp["SEVEN"] = "9";    mp["EIGHT"] = "0";    mp["NINE"] = "1";    cin >> line;    while (line)    {        cin >> s;        sChar = s.c_str();        for (it = mp.begin(); it != mp.end(); it++)        {            p = sChar;            while (p)            {                p = strstr(p, (it->first).c_str());                if (p != NULL)                {                    v.push_back(atoi((it->second).c_str()));                    p = p + it->first.size();                }            }        }        sort(v.begin(), v.end());        for (int i = 0; i < v.size(); i++)            cout << v[i];        cout << endl;        v.clear();        line--;    }    system("pause");    return 0;}
1 0
原创粉丝点击