zoukankan      html  css  js  c++  java
  • 把一个字符串转化成数字表示

    题目大意: 把一个字符串转化成数字表示。AAAA-->4A

    解题思路: 直接统计。

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 
     4 char s[100005];
     5 
     6 void solve()
     7 {
     8     int i = 0;
     9     int cnt = 1;
    10     char tmp = s[0];
    11     for (i = 1; s[i]; ++i)
    12     {
    13         if (s[i] == tmp)
    14         {
    15             ++cnt;
    16         }
    17         else
    18         {
    19             printf("%d%c", cnt, tmp);
    20             cnt = 1;
    21             tmp = s[i];
    22         }
    23     }
    24     printf("%d%c
    ", cnt, tmp);
    25 }
    26 
    27 int main()
    28 {
    29     while (scanf("%s", s) != -1)
    30     {
    31         solve();
    32     }
    33     return 0;
    34 }
  • 相关阅读:
    Python(多进程multiprocessing模块)
    Python(队列)
    Unique Paths
    Unique Paths
    Jump Game II
    Jump Game
    Path Sum II
    Path Sum
    Remove Element
    Implement strStr()
  • 原文地址:https://www.cnblogs.com/djingjing/p/8715105.html
Copyright © 2011-2022 走看看