Huawei Machine Test-Find word sort in string

Source: Internet
Author: User
Tags strtok


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

#include <stdio.h> #include <string.h> #include <stdlib.h>void my_word (char Input[],char output[]) {  Char *p;      Char *temp;     Char *word[10];      int Len_input=strlen (input);      int i,j;      Char except[] = ",";      Char *blank = ""; for (i=0;i<len_input;i++) {if (input[i]< ' A ' | | (input[i]> ' Z ' &&input[i]< ' a ') | |          Input[i]> ' Z ') {input[i]= ', ';      }} j=0;      /* Save the removed word */p= strtok (input,except);          while (null!=p) {word[j++]=p;      p= strtok (null,except);    } for (i=0;i<j;i++) printf ("%s", Word[i]);p rintf ("\ n"); int wordlen=j; /* Sort words in descending order of length, bubbling method */For (i=0;i<wordlen;i++) {for (j=1;j<wordlen-i;j++) {i                  F (strlen (Word[j-1]) <strlen (Word[j])) {temp=word[j];                  WORD[J]=WORD[J-1];              Word[j-1]=temp;   }}}/* Delete the same word */   for (i=0;i<wordlen;i++) {for (j=i+1;j<wordlen;j++) {if (strcmp (word[i],word[j          ]) word[j]= "==0";        }//* Connect the word output */for (j=0;j<wordlen;j++) {if (j==0) strncpy (Output,word[j],strlen (word[j]) +1);              else {strcat (Output,blank);          strcat (Output,word[j]);  }}} int main () {char input[] = "Some local buses, some1234123drivers";    printf ("String before Filtering:%s\n", input);      Char output[30];      My_word (Input,output);      printf ("Filtered string:%s", output);      printf ("\ n");  return 0;   }

Huawei Machine Test-Find word sort in string

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.