蒟蒻求助!!!
  • 板块题目总版
  • 楼主Linktux
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/11/17 21:26
  • 上次更新2023/11/17 22:56:11
查看原帖
蒟蒻求助!!!
1185284
Linktux楼主2023/11/17 21:26

P2562 [AHOI2002] Kitty猫基因编码 显示CE,请大佬帮忙debug+解释

CE评测信息:
/tmp/compiler_9o5tzp1v/src: 在函数‘void gene(std::string)’中:
/tmp/compiler_9o5tzp1v/src:10:14: 错误:‘substr’ was not declared in this scope; did you mean ‘strstr’?
   10 |         gene(substr(0,s.length()/2));
      |              ^~~~~~
      |              strstr
代码:
#include <bits/stdc++.h>
using namespace std;
void gene(string s){
    int sum=0,sum_=0;
    for(int i=0;i<(int)s.length();i++)s[i]-'0'?sum_++:sum++;
    if(sum==(int)s.length())cout<<'A';
    else if(sum_==(int)s.length())cout<<'B';
    else{
        cout<<'C';
        gene(substr(0,s.length()/2));
        gene(substr(s.length()/2,s.length()/2));
    }
}
int main(){
    string s;
    cin>>s;
    gene(s);
    return 0;
}
2023/11/17 21:26
加载中...