当前位置:网站首页>MFC implementation of ACM basic questions encoded by the number of characters

MFC implementation of ACM basic questions encoded by the number of characters

2022-07-04 16:18:00 bcbobo21cn

The English description of the problem is as follows ;

Problem Description

Given a stringcontaining only 'A' - 'Z', we could encode it using the following method:

1. Each sub-string containing k same characters should be encoded to"kX" where "X" is the only character in this sub-string.

2. If the length of the sub-string is 1, '1' should be ignored.

Input

The first linecontains an integer N (1 <= N <= 100) which indicates the number of testcases. The next N lines contain N strings. Each string consists of only 'A' -'Z' and the length is less than 10000.

Output

For each testcase, output the encoded string in a line.

for example , Enter the following two lines ,
ABC
ABBCCC

The output of
ABC
A2B3C

Console C++ The program and output are as follows ;

#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
 
//	const int MAXN=10005;
char a[10005];
int main()
{
    int i,temp;
    int T;
    scanf("%d",&T);// Two sets of test data  
    while(T--)
    {
        scanf("%s",&a);// The input is a string  
        i=0;
        while(a[i]!='\0')// This is the sign to judge the end of the string  
        {
            temp=i;
            while(a[temp+1]==a[i])
            {
                temp++;
            }    
            if(temp>i)
			printf("%d",temp-i+1);
            printf("%c",a[i]);
            i=temp;
            i++;
        } 
        printf("\n");   
    } 
    return 0;   
}

 

VC++2012 Create a new dialog project ;

void CcencDlg::OnBnClickedButton1()
{
		// TODO:  Add control notification handler code here 
		//char a[100];
		CString strc, stre;
		int i,temp;
		CString str1;

		GetDlgItem(IDC_EDIT1)->GetWindowTextW(strc);
		i=0;
        while(i<strc.GetLength()) 
        {
            temp=i;
            while(strc.GetAt(temp+1)==strc.GetAt(i))
            {
                temp++;
            }    
            if(temp>i)
			{
				//printf("%d",temp-i+1);
				str1.Format(_T("%d"),temp-i+1);
				stre.Append(str1);
			}
            //printf("%c",a[i]);
			stre.Append((CString)strc.GetAt(i));
            i=temp;
            i++;
        }
		SetDlgItemText(IDC_EDIT2,stre);
}

  Operation of the ;

 

 

 

 

原网站

版权声明
本文为[bcbobo21cn]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202141147001833.html