Huawei on-Topic summary (10)

Source: Internet
Author: User

Huawei on-Topic summary (10)

Note: The compilation environment is Visual Studio 2012, and the answer is for informational purposes only.

Directory

    • Huawei on the computer problem summary Ten
      • Directory
      • Question 46th
      • Question 47th
      • Question 48th
      • Question 49th
      • Question 50th

Question 46th

46. Find the word in the given string ("word" consists of uppercase and lowercase alphabetic characters, other non-alphabetic characters are treated as intervals of words, such as spaces, question marks, numbers, etc.); After a word is found, it is sorted in descending order of length (if it is the same length when sorting, are arranged in the order in which they appear), and then output to a new string, and if a word repeats multiple times, it is output only once, and if no word is 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 <iostream>#include <string>#include <list>using namespace STD;BOOLIsletter (Charc) {return(c >=' A '&& C <=' Z ');}voidMy_word (Char*input,Char* Output) { list<string>V while(*input! =' + ')    {if(!isletter (*input)) {input++;Continue; }Char*ahead = input; while(*ahead! =' + '&& Isletter (*ahead)) {ahead++; }stringTMP (Input,ahead);Autob = V.begin ();BOOLFlag =true; while(b! = V.end ()) {if((*b). Size () < Tmp.size ()) { Break; }if((*b). Size () = = Tmp.size ()) {if(*b = = tmp) {flag =false; Break;        }} b++; }if(flag) V.insert (b, TMP);    input = ahead; }Autob = V.begin (); while(b! = V.end ()) { for(unsignedj =0; J < (*B). Size ();        J + +) {*output++ = (*b) [j]; } b++;if(b! = V.end ()) {*output++ ="'; }} *output =' + ';}intMain () {Charinput[ -],output[ -];Cin. getline (Input, -); My_word (input, output);cout<< output << Endl;return 0;}
Question 47th

47. The number in the array is 22 the same, only one difference, find the number:

#include <iostream>using namespace STD;intFinddiffence (intA[],intN) {intsum =0; for(inti =0; I < n;    i++) {sum ^= a[i]; }returnsum;}intMain () {intA[] = {2,8,5,4,5,2,8};cout<< Finddiffence (A,7) << Endl;return 0;}
Question 48th

48. The number 22 in the array is the same, there are two different, find out the two

#include <iostream>using namespace Std;intFinddiffence (intA[],intN) {int sum=0; for(inti =0; I < n; i++) {sum^= A[i]; }return sum;}voidFindtwodiffence (intA[],intNint&AMP;RESULT1,int&AMP;RESULT2) {int*TMP1 =New int[n], N1 =0;int*TMP2 =New int[n], N2 =0;int sum=0; for(inti =0; I < n; i++) {sum^= A[i]; }intCMP =sum& a[0]; for(inti =0; I < n; i++) {if((sum& A[i]) = = CMP) {tmp1[n1++] = A[i]; }Else{tmp2[n2++] = A[i];    }} RESULT1 = Finddiffence (TMP1,N1);    RESULT2 = Finddiffence (TMP2,N2);    delete []tmp1; delete []tmp2;}intMain () {intA[] = { +, -, *,4, *, +, -,6};intRESULT1, RESULT2; Findtwodiffence (A,8, RESULT1,RESULT2); cout << RESULT1 <<" "<< result2 << Endl;return 0;}
Question 49th

49. Statistics of the number of occurrences, the maximum number of statistics out
Example:
Input: 323324423343
Output: 3,6

#include <iostream>#include <string>using namespace STD;intMain () {stringSCin>> s;inta[Ten]; for(inti =0; I <Ten; i++) {A[i] =0; }BOOLFlag =true; for(unsignedi =0; I < s.size (); i++) {if(S[i] <' 0 '|| S[i] >' 9 ') {flag =false;cout<<"ERROR"<< Endl; Break; } A[s[i]-' 0 ']++; }if(!flag)return 0;intmax = a[0]; for(inti =1; I <Ten; i++) {if(A[i] > Max)        {max = a[i]; }    } for(inti =0; I <Ten; i++) {if(A[i] = = max) {cout<< I <<","<< A[i] << Endl; }    }return 0;}
Question 50th

50. The first letter of the string is converted to uppercase
Example:
Input: This was a book
Return: This is A book

BOOL Isletter (char c) {return(c >=' A '&& C <=' Z ');} void Convert (char*input, Char*output){ while(*input!=' + ')    {if(!isletter (*input))        {*output++ =*input++;Continue; }*output+ + = ToUpper (*input++); while(*input!=' + '&& Isletter (*input))        {*output++ =*input++; }    }*output=' + ';}intMain () {char input[ -],output[ -]; Cin.getline (Input, -);    Convert (input,output); cout << output << Endl;return 0;}

Huawei on-Topic summary (10)

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: info-contact@alibabacloud.com 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.