31: The longest consecutive character in a string, and the longest character in a 31 string

Source: Internet
Author: User

31: The longest consecutive character in a string, and the longest character in a 31 string
31: The longest consecutive character in a string

  • View
  • Submit
  • Statistics
  • Question
Total time limit:
1000 ms
 
Memory limit:
65536kB
Description

Returns the longest consecutive character in a string and the number of occurrences of the character. The string contains no blank characters (space, carriage return, and tab). If there are more than one such character, the earliest character is output.

Input
A line. It is a string that does not contain white spaces. the string length is less than 200 characters.
Output
For a row, the maximum consecutive characters and the maximum number of consecutive occurrences are output. Separate them with a space in the middle.
Sample Input
aaaaadbbbbbcccccccdddddddddd
Sample output
d 10
Source
6373
 1 #include<iostream> 2 #include<cstdio> 3 #include<queue> 4 #include<cmath> 5 #include<cstring> 6 using namespace std; 7 char a[10001]; 8 int now; 9 int maxn=-1;10 char ans;11 int main() 12 {13     gets(a);14     int l=strlen(a);15     for(int i=0;i<l;i++)16     {17         if(a[i]==a[i+1])18         now++;19         else20         {21             now++;22             if(now>maxn)23             {24                 maxn=now;25                 ans=a[i];26             }27             now=0;    28         }29     }30     cout<<ans<<" "<<maxn;31     return 0;32 }

 

Related Article

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.