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;
}
相關文章
- 1020-1026
- ## HTTP系列之Accept-Encoding和Content-EncodingHTTPEncoding
- [特徵工程] encoding特徵工程Encoding
- PAT-B1020 月餅
- 1020:列印ASCII碼(C C++)ASCIIC++
- PAT:1020. Tree Traversals (25) AC
- hdu 2111 Saving HDU (DP)
- Enhanced Invertible Encoding for Learned Image CompressionEncoding
- [HTTP] HTTP 協議 Response Header 之 Content-Length、Transfer-Encoding與Content-EncodingHTTP協議HeaderEncoding
- PAT-B 1020 月餅【貪心法】
- ELF file data encoding not little-endianEncoding
- 1020 月餅 (25分) + 測試點解析
- 洛谷 P1020 導彈攔截
- but no encoding declared;問題的解決方法Encoding
- PostgreSQL DBA(103) - pgAdmin(Don't do this:Encoding)SQLEncoding
- Transformer中的位置編碼(Positional Encoding)ORMEncoding
- PAT B1020 月餅(簡單貪心)
- Shape of HDU
- HDU 3349
- HDU 2052(C語言+註釋)+HDU 2090C語言
- 簡單的揹包問題(入門)HDU2602 HDU2546 HDU1864
- HDU 3661 Assignments
- hdu 6415 - DP
- HDU4787
- hdu2083
- hdu5540
- HDU 4921 Map
- hdu5532
- HDU 1240 Asteroids!AST
- ERROR:Failed to load resource: net::ERR_INCOMPLETE_CHUNKED_ENCODINGErrorAIEncoding
- 連線DB2時出錯:encoding not supported??DB2Encoding
- HDU6415(DP)
- HDU 3400 Line belt
- HDU 1236 排名(Java)Java
- hdu1025javaJava
- hdu1069javaJava
- HDU Find the hotel(RMQ)MQ
- HDU 6060 RXD and dividing
- Switch Game HDU - 2053GAM