[Interview question 001] Find all the letters that have not appeared in the sentence

Source: Internet
Author: User

If a sentence contains all the letters, It is called pangrams. For example:
"A quick brown fox Jumps over
The lazy dog "is a pangrams.

Write a C ++ function, string getmissingletters (const string &
SA)
Sa represents an input sentence.
If SA is not pangrams, the function should output all letters missing from SA. The output letters should be alphabetically arranged.

BTW:
Uppercase and lowercase letters are output.

# Include <iostream> <br/> # include <string> <br/> using namespace STD; <br/> string getmissingletters (const string & SA ); <br/> int _ tmain (INT argc, _ tchar * argv []) <br/>{</P> <p> // string strsentence = "jumps over the lazy dog"; <br/> string strsentence = ""; <br/> string missingletters = getmissingletters (strsentence); <br/> cout <missingletters <Endl; <br/> return 0; <br/>}< br/> string getmissingletters (const string & SA) <br/>{< br/> int letterfre [256] = {0 }; <br/> int occurletternum = 0; <br/> for (INT I = 0; I <SA. size (); I ++) <br/>{< br/> char CH = sa [I]; <br/> // if it is a capital letter, convert it to lower case <br/> If (CH> = 'A' & Ch <= 'Z ') <br/>{< br/> CH = 'A' + (CH-'A '); <br/>}< br/> // If (CH <'A' | ch> 'Z ') <br/>{< br/> continue; <br/>}< br/> // count the number of letters that have occurred <br/> If (letterfre [(INT) ch] = 0) <br/>{< br/> occurletternum ++; <br/>}< br/> letterfre [(INT) CH] ++; <br/>}< br/> // Of course, 26-occurletternum is not displayed. <br/> string missletters (26-occurletternum ,''); </P> <p> // extract unused letters <br/> int COUNT = 0; <br/> for (INT I = 'a '; I <= 'Z'; I ++) <br/>{< br/> If (letterfre [I] = 0) <br/>{< br/> missletters [count ++] = (char) I; <br/>}< br/> return missletters; <br/>}

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.