哥哥姐姐 大佬们 help 这个错误我该怎么改

P1320 压缩技术(续集版)

cyh0228 @ 2023-08-29 09:52:29

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
char a[1000];
int b[1000]={0};
int en=1,sum=1,b1=1;
int main()
{
    scanf("%s", a);
    for(int i=1;a[i]!='\0';i++)
    {
        sum++;
    }
    for(int i=2;i<+sum*sum;i++)
    {
        if(i>sum)
        {
          a[i]=getchar();
          if(a[i]==a[i-1])
          {
              b[b1]++;
          } 
          else
          {
              b1++;
          }

        }
        else
        {
            if(a[i]==a[i-1])
            {
                b[b1]++;
            }//报错点22    11  P1320 5.cpp [Error] stray '\241' in program
            else
            {
                b1++;
            }
        }

    }
    for(int i=1;i<=b1;i++)
    cout<<b[i];
    return 0;
}

by syr1125 @ 2023-08-29 09:56:25

玄学错误


by cyh0228 @ 2023-08-29 09:59:23

@syr1125 我也这么认为 应该是他口渴了 想和水


by syr1125 @ 2023-08-29 09:59:37

ok,改好了

#include <bits/stdc++.h>
using namespace std;

string s[205];
int n, cnt0, cnt1;
bool flag;

void print(string a)
{
    for (int i = 0; i < a.size(); i ++)
    {
        bool t = a[i] - '0';
        if (t == flag)
        {
            if (flag) cnt1 ++;
            else cnt0 ++;
        }
        else
        {
            if (cnt1) cout << cnt1 << " ";
            else cout << cnt0 << " ";
            cnt1 = cnt0 = 0;
            flag = !flag;
            i --; 
        }
    }
}

int main()
{
    cin >> s[1];
    n = s[1].size();
    flag = false;
    for (int i = 2; i <= n; i ++)
    {
        cin >> s[i];
    }
    cout << n << " ";
    for (int i = 1; i <= n; i ++) print(s[i]);
    if (cnt0) cout << cnt0 << " ";
    else cout << cnt1 << " "; 
    return 0;
}

by cyh0228 @ 2023-08-29 09:59:44

@cyh0228 喝


by syr1125 @ 2023-08-29 10:00:18

原因


by cyh0228 @ 2023-08-29 10:02:07

@syr1125 欧克 欧克 谢谢您 感谢您的回复


|