POJ C Programming Advanced Programming Question # #: The number of the 2nd letter in a string

Source: Internet
Author: User

Programming Question #: Number 2nd in a string

Source: POJ (Coursera statement: The exercises completed on POJ will not count against the final results of Coursera. )

Note: Total time limit: 1000ms memory limit: 65536kB

Describe

Enter a string of no more than 500 symbols, the output appears in the string of the 2nd more English letters (uppercase and lowercase letters are considered the same) and the number of times (if there are other symbols in the string, ignore regardless). If the number of letters is more than 2nd, the 1th is output in the order in which the letters appear in the string.

Example AB&DCAAB&C9DEFGB

Here, both A and B appear 3 times, both C and D appear 2 times, E, F and G appear 1 times, with symbols & and 9 ignored. Therefore, the 2nd more should be C and D, but D begins to appear in front of C, so the output is

D+d:2

(assuming that in a string, the number of the 2nd-most letters always exists)

Input

A string

Output

Uppercase letter + lowercase letters: number

Sample input
Ab&dcaab&c9defgb
Sample output
D+d:2
1#include <stdio.h>2#include <iostream>3 using namespacestd;4 5 structCharandnum {6     Charch;7     intcount;8 };9 intMain () {Ten     structCharandnum s[501], Max, second; One     Chara[501]; ACin>>A; -     intI, j, L =0; -      for(i =0; A[i]! =' /'; i++) { the         if((A[i] >='A'&& A[i] <='Z') || (A[i] >='a'&& A[i] <='Z')) { -             Chartemp; -             if(A[i] >='a') -temp = A[i]- +; +             Else -temp =A[i]; +             BOOLFound =false; A              for(j =0; j< l; J + +) { at                 if(s[j].ch = =temp) { -s[j].count++; -Found =true; -                 } -             } -             if(!found) { ins[l].ch =temp; -S[l].count =1; tol++; +             } -         } the     } *max = s[0]; $     BOOLFoundsecond =false;Panax Notoginsengi =0; -      while(!Foundsecond) { the         if(S[i].count >max.count) { +Second =Max; AMax =S[i]; theFoundsecond =true; +         } -         Else if(S[i].count <max.count) { $Second =S[i]; $Foundsecond =true; -         } -i++; the     } -      for(i; i<l-1; i++) {Wuyi         if(S[i].count >max.count) { theSecond =Max; -Max =S[i]; Wu}Else if(S[i].count < Max.count && S[i].count >second.count) { -Second =S[i]; About         } $     } -printf"%c+%c:%d\n", second.ch, (Char) (second.ch + +), second.count); -     return 0; -}

POJ C Programming Advanced Programming Question # #: The number of the 2nd letter in a 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: 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.