P1055 ISBN报错求救!

P1055 [NOIP2008 普及组] ISBN 号码

HaloCode @ 2024-03-17 09:19:36

代码如下

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    int cnt = 2, he = 0, zong = 0, shibiema;
    string isbn;
    getline(cin, isbn);
    he = isbn.at(0) * 0;
    for(int i = 2; i <= 4; i++){
        he = isbn.at(i) * cnt;
        zong += he;
        cnt++;
    }
    for(int i = 6; i <= 10; i++){
        he = isbn.at(i) * cnt;
        zong += he;
        cnt++;
    }

    shibiema = zong % 11;
    char a;
    a = shibiema - '0';
    if(shibiema == isbn.at(12)){
        cout << "right";
    }else{
        isbn.replace(12, (char)(a));
        cout << isbn;
    }
}

报错:

[错误] no matching function for call to 'std::__cxx11::basic_string<char>::replace(int, char)'


by B_neutrino @ 2024-03-17 09:31:34

replace函数的两个参数都应该是char类型,具体百度上看


by Service_Unavailable @ 2024-03-17 09:32:58

@dadudu1115 对'std::__cxx11::basic_string<char>::replace(int,char'的调用没有匹配的函数 Emmmm......也就是说,你的头文件没对上号呗,加个万能头就不报错了不是??


by Charles_with_wkc @ 2024-03-17 09:50:25

@dadudu1115 建议以后使用#include<bits/stdc++.h> 万能头文件,避免考试出现这样的错误


by HaloCode @ 2024-03-17 10:01:17

我改成at函数就可以了


by Null_in_null @ 2024-03-17 10:16:23

@dadudu1115 万能头加define int long long signed main永不爆炸。

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

signed main( ) {
    return 0 ;
}

by HaloCode @ 2024-03-17 10:31:53

@IAKIOI___ 好家伙可以啊你


|