zoukankan      html  css  js  c++  java
  • PAT 乙级 1084. 外观数列 (20) 【字符串】

    题目链接

    https://www.patest.cn/contests/pat-b-practise/1084

    思路
    用字符串模拟

    然后要注意一点 它是连续的 才并在一起

    就比如说

    d, d1, d111, d113, d11231, d112213111, …

    比如 d11231 -> d112213111

    是 1个d 2 个 1 1 个 2 1 个 3 1 个 1

    然后 并在一起就是

    d112213111

    而不是 d1132131

    AC 代码

    #include <cstdio>
    #include <cstring>
    #include <ctype.h>
    #include <cstdlib>
    #include <cmath>
    #include <climits>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <deque>
    #include <vector>
    #include <queue>
    #include <string>
    #include <map>
    #include <stack>
    #include <set>
    #include <numeric>
    #include <sstream>
    #include <iomanip>
    #include <limits>
    
    #define CLR(a) memset(a, 0, sizeof(a))
    #define pb push_back
    
    using namespace std;
    typedef long long ll;
    typedef long double ld;
    typedef unsigned long long ull;
    typedef pair <int, int> pii;
    typedef pair <ll, ll> pll;
    typedef pair<string, int> psi;
    typedef pair<string, string> pss;
    
    const double PI = 3.14159265358979323846264338327;
    const double E = exp(1);
    const double eps = 1e-30;
    
    const int INF = 0x3f3f3f3f;
    const int maxn = 1e5 + 5;
    const int MOD = 1e9 + 7;
    
    string tran(string s)
    {
        int len = s.size();
        string ans = "";
        char c = s[0];
        int num = 1;
        for (int i = 1; i < len; i++)
        {
            if (s[i] == c)
                num++;
            else
            {
                ans += c;
                ans += num + '0';
                c = s[i];
                num = 1;
            }
        }
        ans += c;
        ans += num + '0';
        return ans;
    }
    
    int main()
    {
        string ans;
        cin >> ans;
        int n;
        cin >> n;
        for (int i = 1; i < n; i++)
            ans = tran(ans);
        cout << ans << endl;
    }
    
    
    
    
    
    
    
  • 相关阅读:
    vue改变了数据却没有自动刷新
    Unable to find vcvarsall.bat
    修改Linux用户配置之后先验证再退出
    平面最远点对
    [转]你可能不知道的五个强大HTML5 API
    sqlite3常用技巧
    使用rsync
    画图必备numpy函数
    np.percentile获取中位数、百分位数
    [转]numpy 100道练习题
  • 原文地址:https://www.cnblogs.com/Dup4/p/9433201.html
Copyright © 2011-2022 走看看