【发布时间】:2013-10-01 01:03:09
【问题描述】:
我正在尝试将数字乘以它们的索引以创建哈希,但这似乎没有给出正确的输出。谁能告诉我这里出了什么问题?
int main(){
int i, hash=0, input;
char temp[30];
cin>>input;
itoa (input, temp, 10);
for(i=0; i<(sizeof(temp)/sizeof(*temp)); i++){
hash+=((temp[i])*i);
}
cout<<hash;
return 0;
}
【问题讨论】:
-
为什么不直接做
string str; cin >> str?另外,你真的不应该使用using。 -
itoa既不是标准 C 也不是 C++ 函数。