当前位置:网站首页>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 ;
边栏推荐
- Unity script API - GameObject game object, object object
- The new generation of domestic ORM framework sagacity sqltoy-5.1.25 release
- C language: implementation of daffodil number function
- Unity动画Animation Day05
- 在芯片高度集成的今天,绝大多数都是CMOS器件
- 中国主要城市人均存款出炉,你达标了吗?
- The per capita savings of major cities in China have been released. Have you reached the standard?
- What does IOT engineering learn and work for?
- Scientific research cartoon | what else to do after connecting with the subjects?
- Functional interface, method reference, list collection sorting gadget implemented by lambda
猜你喜欢
Scientific research cartoon | what else to do after connecting with the subjects?
Function test - knowledge points and common interview questions
这几年爆火的智能物联网(AIoT),到底前景如何?
[native JS] optimized text rotation effect
Talking about Net core how to use efcore to inject multiple instances of a context annotation type for connecting to the master-slave database
Audio and video technology development weekly | 252
Data Lake Governance: advantages, challenges and entry
AI做题水平已超过CS博士?
Actual combat | use composite material 3 in application
Unity脚本常用API Day03
随机推荐
AI system content recommendation issue 24
Working group and domain analysis of Intranet
[book club issue 13] packaging format and coding format of audio files
%F format character
MySQL学习笔记——数据类型(2)
Unity script introduction day01
MySQL index optimization
Redis' optimistic lock and pessimistic lock for solving transaction conflicts
Essential basic knowledge of digital image processing
Selenium element interaction
Unity script API - transform transform
Socks agent tools earthworm, ssoks
AI做题水平已超过CS博士?
Qt---error: ‘QObject‘ is an ambiguous base of ‘MyView‘
Talking about Net core how to use efcore to inject multiple instances of a context annotation type for connecting to the master-slave database
Implementation of web chat room
LeetCode 1184. 公交站间的距离 ---vector顺逆时针
MySQL学习笔记——数据类型(数值类型)
Will the memory of ParticleSystem be affected by maxparticles
Function test - knowledge points and common interview questions