HDU 1020 Encoding
Encoding
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 26148 Accepted Submission(s): 11511
Problem Description
Given a string containing 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.
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 line contains an integer N (1 <= N <= 100) which indicates the number of test cases. The next N lines contain N strings. Each string consists of only 'A' - 'Z' and the length is less than 10000.
Output
For each test case, output the encoded string in a line.
Sample Input
2
ABC
ABBCCC
Sample Output
ABC
A2B3C
感覺這題怪怪的
#include<stdio.h>
#include<string.h>
char a[11000];
int main()
{
int n,i,j,k;
scanf("%d",&n);
while(n--)
{
scanf("%s",a);
for(i=0;a[i]!='\0';i++)
{
for(j=i,k=0;j<strlen(a);k++,j++)
{
if(a[i]!=a[j])
break;
}
if(k>1)
printf("%d",k);
printf("%c",a[i]);
i=j-1; //把 i 限制到第二個for迴圈處 j 所處的位置
}
printf("\n");
}
return 0;
}
相關文章
- [Encoding]How to do proper encoding output redirection on cmd.exe?Encoding
- [特徵工程] encoding特徵工程Encoding
- ## HTTP系列之Accept-Encoding和Content-EncodingHTTPEncoding
- 1020-1026
- 1020:列印ASCII碼(C C++)ASCIIC++
- PEM (Privacy Enhanced Mail) EncodingAIEncoding
- 關於Encoding問題Encoding
- 1020 月餅 (25分) + 測試點解析
- 洛谷 P1020 導彈攔截
- Encoding/Decoding 高階教程 [生肉]Encoding
- iconvvsmb_convert_encodingEncoding
- [HTTP] HTTP 協議 Response Header 之 Content-Length、Transfer-Encoding與Content-EncodingHTTP協議HeaderEncoding
- ELF file data encoding not little-endianEncoding
- windows10BashOnWindowsERR_INCOMPLETE_CHUNKED_ENCODINGWindowsEncoding
- Enhanced Invertible Encoding for Learned Image CompressionEncoding
- but no encoding declared;問題的解決方法Encoding
- SG 函式初步 HDU 1536 && HDU 1944函式
- 字符集和字元編碼(Charset & Encoding)字元Encoding
- 比 encoding/json 更快地解析 jsonEncodingJSON
- Android @Field parameters can only be used with form encodingAndroidORMEncoding
- HTTP 協議中的 Content-EncodingHTTP協議Encoding
- content-length 與 transfer-encoding=chunkedEncoding
- utf8encoding類_編碼_解碼Encoding
- Transformer中的位置編碼(Positional Encoding)ORMEncoding
- Shape of HDU
- HDU4787
- hdu5532
- OpenAI ChatGPT 錯誤碼 1020 怎麼解決?3 種方法OpenAIChatGPT
- PostgreSQL DBA(103) - pgAdmin(Don't do this:Encoding)SQLEncoding
- 連線DB2時出錯:encoding not supported??DB2Encoding
- Node.js Base64 Encoding和DecodingNode.jsEncoding
- How to: Select an Encoding for ASP.NET Web Page GlobalizationEncodingASP.NETWeb
- HDU 2052(C語言+註釋)+HDU 2090C語言
- HDU Find the hotel(RMQ)MQ
- HDU1792(公式)公式
- hdu 2846 Repository
- hdu 1695 GCDGC
- HDU 2051 Bitset