Topic:
Finds the word in the given string (the word is made up of uppercase and lowercase alphabetic characters, and other non-alphabetic characters are treated as intervals of words, such as spaces, question marks, numbers, and so on; the other individual letters are not words) , and then output to a new string, and if a word recurs multiple times, output only once, and if the word is not found in the entire input string, output an empty string. The output words are separated by a "space", with no spaces after the last word.
Required implementation functions:
void My_word (charinput[], char output[])
"Enter" Char input[], enter the string
"Output" char output[], the output string
"Back" none
Example:
Input: charinput[]= "Some local buses, some1234123drivers",
Output: charoutput[]= "drivers local buses some"
Input: charinput[]= "%a^123 t 3453i* ()",
Output: charoutput[]= ""
#include <iostream> #include <string> #include <vector> #include <algorithm>using namespace std ; bool MyFunction (const string &str1,const string &str2) {return (Str2.length () < Str1.length ());} void My_word (char input[],char output[]) {vector<string> str;char*cur = Input;char*p = Input;int Len;bool flag =fals e;//remove impurities, take word while (*p! = ') ' {if ((*p >= ' a ' &&*p <= ' z ') | | (*p >= ' A ' &&*p <= ' Z ')) P++;else{len = p-cur;if (len >1) {string tmp (Cur,len); for (int i=0;i<str.size (); i++) if (tmp = = Str[i]) flag =true;if ( Flag!=true) Str.push_back (TMP);} cur = P+1;p++;flag =false;}} Len = p-cur;if (len >1) {string tmp (Cur,len); for (int i=0;i<str.size (); i++) if (tmp = = Str[i]) flag =true;if (Flag! = true) Str.push_back (TMP);} Sortsort (Str.begin (), Str.end (), myfunction);//splicing string *output= ' + '; int i;for (I=0;i<str.size () -1;i++) {strcpy ( Output+strlen (output), (str[i]+ ""). C_str ());} strcpy (Output+strlen (Output), (Str[i]). C_STR ()); Cout<<output<<endl;} int MAIn () {char input[]= "some ninja local buses, somes1234123drivers"; Char output[500];my_word (input, output); return 0;}
Huawei Machine Test-Find the word in the given string