#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;
}
预期&#39;;&#39;之前&#39;}&#39;令牌???在第80:7行,这是这部分
ptr->next=newptr;
location:
}
我在我的智慧结束...我尝试了很多方法来调试,问题与GOTO功能有关,但我真的看不出任何问题!
答案 0 :(得分:8)
你没有。替换:
ptr->next=newptr;
location:
}
与
ptr->next=newptr;
location:; // <-- empty statement
}
这是语言的语法:语句必须遵循标签,至少是空标签。
答案 1 :(得分:2)
C ++标准定义labeled statement
。这意味着标签只能在声明之前。标签声明(缩写)的定义如下所示
identifier : statement
所以这个结构
location:
}
无效,因为标签不在任何语句之前。 如果您希望将控件传递到代码块的末尾,则可以使用null语句。例如
location: ;
}
来自C ++标准
null语句对于在复合语句的}之前携带标签很有用 为迭代语句(如while语句)提供null主体