gpt4 book ai didi

c++ - 为什么我的编译器期望标签处的 ';' 标记之前是 '}'?

转载 作者:太空狗 更新时间:2023-10-29 23:40:05 28 4
gpt4 key购买 nike

<分区>

#include <iostream>
#include <string>
#include <cstring>
#include <vector>

using namespace std;

struct node {
int number;
string name;
node* next;
};

int hash(string dna) {
int i, sum=0;
for (i=0; i<dna.size(); i++) {
if (dna[i]=='A') {
}
else if (dna[i]=='C') {
sum+=1;
}
else if (dna[i]=='G') {
sum+=2;
}
else {
sum+=3;
}
}
cout << "Hash sum is " << sum << endl;
return sum;
}

int main() {
//input
int dnalength, sublength;
cin >> dnalength >> sublength;
string sequence;
cin >> sequence;
//Declare array
vector <node*> list(sublength*3+1);
cout << "The list size is " << list.size() << endl;
//Storing all substrings
int index;
for (index=0; index+sublength-1<dnalength; index++) {
string temp = sequence.substr(index, sublength);
cout << "Current substring is " << temp << endl;
int value = hash(temp);
if (list[value]==NULL) {
//cout << "Null activated " << endl;
//Node declaration
node* ptr;
ptr = new node;
ptr->number=1;
ptr->name=temp;
ptr->next=NULL;

list[value]=ptr;
}
else {
node* ptr=list[value];
while (ptr->next!=NULL) {
if (ptr->name==temp) {
ptr->number++;
goto location;
}
ptr=ptr->next;
}
if (ptr->name==temp) {
ptr->number++;
goto location;
}
node* newptr;
newptr = new node;
newptr->number=1;
newptr->name=temp;
newptr->next=NULL;

ptr->next=newptr;
location:
}
cout << "Success 1 loop " << endl;
}
cout << "Debug @ 3: " <<list[3]->name << list[3]->number << endl;
cout << "Debug @ 3: " <<(list[3]->next)->name << (list[3]->next)->number << endl;

int numofsub;
cin >> numofsub;

return 0;
}

预期';'在 '}' 标记之前 ???第80:7行,也就是这部分

         ptr->next=newptr;
location:
}

我束手无策...我尝试了很多方法来调试,问题与 GOTO 函数有关,但我真的看不出有任何问题!

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com