C language AABBCC, ABC, FABC, AABC

Source: Internet
Author: User

Enter a string that matches the contiguous string in the string, and the number of consecutive occurrences is equal

such as input AABBCC, ABC, FABC, AABC, AABBC

Output yes or no, respectively

#include <stdio.h>
#include <string.h>
void Main ()
{
/*
Idea: Enter a string array A, define an array of b[3]={1,0,0} (which is intended to be the default first one that does not need to match)

*/
Char a[]={' f ', ' a ', ' a ', ' a ', ' B ', ' d ', ' C '};

Int b[3]={1,0,0};
int i = 0;
int f = 0;
int g = 0;
int h = 1;
printf ("a===%d\n", sizeof (a));
for (i = 1; i< sizeof (a); i++)
{
printf ("i====%d\n", I);
If a[i-1] = = A[i], the default from a[0] = = a[1], equal to add one, equivalent to a[0]= ' a ' = = a[1]= ' A '
if (a[i-1] = = A[i]) {
B[g] = ++h;
printf ("b[%d]=%d\n", G,b[g]);
}
///Here you only need to determine the unequal
if ((a[i-1]! = A[i]) && (a[i-1]-a[i] = = 1)) {//&& a[i]-a[i+1] = 1
if (a[i-1]- A[i] = =-1) {
H = 1;
g = g+1;
B[g] = h;
}else{
if (g==0) {
B[0] = 1;
B[1] = 0;
B[2] = 0;
}
if (g = = 1) {
B[0] = b[1];
B[1] = 0;
B[2] = 0;
}
if (g = = 2) {
B[0] = b[2];
B[1] = 0;
B[2] = 0;
}

h = 1;
g = 0;
}
}
printf ("%d\n", b[0]);
printf ("%d\n", b[1]);
printf ("%d\n", b[2]);
printf ("-----------------------------\ n");
if (B[0] >= b[1] && b[1]== b[2] && b[2]>=1) {
printf ("yes\n");
Break
}

}

}

C language AABBCC, ABC, FABC, AABC

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.