title: AAA? Bbb? Ccc? divided into: AAA BBB CCC
Examples:
Input: AAA? Bbb? Ccc? ? 2 (that is, enter AAA?) Bbb? CCC? and? and 2)
Output: BBB
Idea code: Use Strtok to intercept the string and use a variable count to load the count and the truncated string into the map for traversal.
1#include <iostream>2#include <string.h>3#include <stdio.h>4#include <map>5 using namespacestd;6 7 CharStrin[] ="AAA? Bbb? CCC?";8 CharSeps[] ="?";9 Char*token;Ten One intMain () A { -map<int,Char*>m; -printf"%s\n\ntokens:\n", Strin); thetoken =strtok (Strin, seps); - intK =1; - while(Token! =NULL) - { +M.insert (pair<int,Char*> (k++, token)); -token =strtok (NULL, seps); + } Amap<int,Char*>:: iterator it; at for(it = M.begin (); It! = M.end (); it++) - { - if(It->first = =2) - { -cout<<it->first<<" "<<it->second<<Endl; - } in - } to}
View Code
Huawei Machine Questions