地址:
点击打开链接
脑壳疼,脑壳疼,哎,写代码几分钟,debug一小时。
还是要说说,指针的问题。
指针的传递,我感觉吃了一点亏。其中最让我不明白的地方是。
如果一个结构体例内的构造函数,不能赋值给一个对象。
struct temp { int p; temp() { p = 0; } }tp;
如果写下面代码会报错:
tp = new temp();出现的错误是这个
||=== Build file: "no target" in "no project" (compiler: unknown) ===| E:\codeblock\nameSpace\t\main.cpp||In function 'int main()':| E:\codeblock\nameSpace\t\main.cpp|71|error: no match for 'operator=' (operand types are 'temp' and 'temp*')| E:\codeblock\nameSpace\t\main.cpp|63|note: candidate: temp& temp::operator=(const temp&)| E:\codeblock\nameSpace\t\main.cpp|63|note: no known conversion for argument 1 from 'temp*' to 'const temp&'| ||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
emmm,我不是很明白,如果有大佬知道的话,麻烦说一下,我就把这个先记下来。
ac代码:
#include<iostream> #include<cstdio> #include<string.h> #include<algorithm> using namespace std ; int Num_key[10]={0,0,3,3,3,3,3,4,3,4}; string res_str ; int res_sum ; string input ; string keys[10]={"*","*","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; struct Node{ Node *next[26]; bool isWord; int fruq; Node(){ for(int i = 0 ; i < 26 ; i ++) next[i]=NULL; isWord = false; fruq = 0 ; } }*root; void insert_Node(string target , int fruq) { Node *p ; p = root ; for(int i =0 ; i <target.length();i++) { if(p->next[target[i]-'a']==NULL) { p->next[target[i]-'a'] = new Node(); } p = p->next[target[i]-'a'] ; p->fruq += fruq; } p->isWord = true ; } void dfs(int current ,int target_length ,Node *node,string res) { if(current == target_length) { if(node->fruq>res_sum) { res_sum = node->fruq; res_str = res ; } //return ; } int t = input[current]-'0'; for(int i = 0 ; i <Num_key[t];i++ ) { if(node->next[keys[t][i]-'a']!=NULL) { dfs(current +1 , target_length, node->next[keys[t][i]-'a'],res+keys[t][i]); } } } int main(){ int T ,t,fruq; string target ; scanf("%d",&T); int index= 1 ; while(T--) { printf("Scenario #%d:\n",index ++); root = new Node(); scanf("%d",&t); while(t--) { cin>>target; cin>>fruq; insert_Node(target,fruq); } scanf("%d",&t); while(t--) { cin>>input; int len = input.length(); for(int i=1;i<len ; i ++) { res_sum = 0 ; dfs(0,i,root,""); if(res_sum) cout <<res_str<<endl ; else cout <<"MANUALLY"<<endl; } cout <<endl ; } cout <<endl ; } return 0 ; }