PAT (Basic Level) Practice (中文)- 1078 字符串压缩与解压(20 分)

简介: PAT (Basic Level) Practice (中文)- 1078 字符串压缩与解压(20 分)

题目链接:点击打开链接

题目大意:略。

解题思路:略。

AC 代码

#include<bits/stdc++.h>
#include<cmath>
#define mem(a,b) memset(a,b,sizeof a);
#define INF 0x3f3f3f3f
#define MOD 1000000007
using namespace std;
typedef long long ll;
int main()
{
    char op;
    string s;
    scanf("%c",&op);
    getchar();
    getline(cin,s);
    int len=s.length();
    if(op=='C')
    {
        int cnt=1;
        for(int i=0;i<len-1;i++)
        {
            if(s[i]==s[i+1]) cnt++;
            else
            {
                if(cnt==1) putchar(s[i]);
                else printf("%d%c",cnt,s[i]);
                cnt=1;
            }
        }
        if(len-2>=0 && s[len-1]==s[len-2]) printf("%d%c",cnt,s[len-1]);
        else putchar(s[len-1]);
    }
    else
    {
        int num=0;
        for(int i=0;i<len;i++)
        {
            if(isdigit(s[i])) num=num*10+(s[i]-'0');
            else
            {
                if(num>0) while(num--) putchar(s[i]);
                else putchar(s[i]);
                num=0;
            }
        }
    }
    puts("");
    return 0;
}
目录
相关文章
完美简单永久解决WEKA中导入arrf文件(包含中文字符)出现“unable to determine structure as arff...”错误
完美简单永久解决WEKA中导入arrf文件(包含中文字符)出现“unable to determine structure as arff...”错误
218 0
完美简单永久解决WEKA中导入arrf文件(包含中文字符)出现“unable to determine structure as arff...”错误
PAT (Basic Level) Practice (中文) 1016 部分A+B (15 分)
PAT (Basic Level) Practice (中文) 1016 部分A+B (15 分)
64 0
|
测试技术
PAT (Basic Level) Practice (中文) B1011 A+B 和 C (15 分)
PAT (Basic Level) Practice (中文) B1011 A+B 和 C (15 分)
76 0
PAT (Basic Level) Practice (中文) B1011 A+B 和 C (15 分)
|
C语言
PAT (Basic Level) Practice (中文) B1026 程序运行时间 (15 分)
PAT (Basic Level) Practice (中文) B1026 程序运行时间 (15 分)
96 0
PAT (Basic Level) Practice (中文) B1046 划拳 (15 分)
PAT (Basic Level) Practice (中文) B1046 划拳 (15 分)
59 0
|
算法
PAT (Basic Level) Practice (中文)1028. 人口普查(20分)
PAT (Basic Level) Practice (中文)1028. 人口普查(20分)
76 0
|
存储 测试技术
PAT (Basic Level) Practice (中文) 1004 成绩排名 (20 分)
PAT (Basic Level) Practice (中文) 1004 成绩排名 (20 分)
63 0
|
人工智能
PAT (Basic Level) Practice (中文)- 1049 数列的片段和(20 分)
PAT (Basic Level) Practice (中文)- 1049 数列的片段和(20 分)
76 0
PAT (Basic Level) Practice (中文)- 1060 爱丁顿数(25 分)
PAT (Basic Level) Practice (中文)- 1060 爱丁顿数(25 分)
78 0
|
存储 人工智能
PAT (Basic Level) Practice (中文)- 1030 完美数列(25 分)
PAT (Basic Level) Practice (中文)- 1030 完美数列(25 分)
71 0