4 条题解

  • 0
    @ 2024-12-29 14:13:05
    #include <bits/stdc++.h>
    
    using namespace std;
    
    typedef long long ll;
    
    int main() {
        string s;
        cin >> s;
    //    ll lens = s.size();
        string ans = "";
        char t = s[0];
        ll cnt = 0;
        for (int i = 0; i < s.size(); i++) {
            if (i - 1 >= 0 && s[i] != t) {
                ans += t;
                ans += to_string(cnt);
                cnt = 0;
            }
            t = s[i];
            cnt++;
        }
        ans += t;
        ans += to_string(cnt);
    
        cout << ans << endl;
        return 0;
    }
    
    • 0
      @ 2024-4-14 17:39:13
      #include<cstdio>
      #include<iostream>
      using namespace std;
      
      int main(){
      	
      	string s;
      	cin>>s;
      	int len=s.length();
      	char now=s[0];
      	int count=1;
      	
      	for(int i=1;i<len;++i){
      		if(s[i]==s[i-1]){
      			count++;
      		}
      		else{
      			cout<<now<<count;
      			count=1;
      			now=s[i];
      		}
      	}
      	
      	cout<<now<<count;
      
      	return 0;
      }
      
      • 0
        @ 2024-4-13 17:07:09
        s = input()
        n = len(s)
        t = 1
        ans = 0
        for i in range(n-1):
            if s[i]==s[i+1]:
                t+=1
            else:
                print(s[i],end = "")
                print(t,end = "")
                t=1
        print(s[i+1],end = "")
        print(t,end = "")
        
        • 0
          @ 2024-4-12 11:59:00
          #include<bits/stdc++.h>
          using namespace std;
          string s;
          int main(){
              ios::sync_with_stdio(0);
              cin.tie(0);
              cout.tie(0);
              cin>>s;
              for(int i=0;i<s.size();){
                  int ans=1;
                  int j=i+1;
                  while(s[j]==s[i]){
                      ans++;
                      j++;
                  }
                      cout<<s[i]<<ans;
                      i=j;
              }
          }
          
          • 1

          信息

          ID
          65
          时间
          1000ms
          内存
          256MiB
          难度
          3
          标签
          递交数
          155
          已通过
          84
          上传者