📄 wex14_18.cpp
字号:
#include <iostream.h>
#pragma hdrstop
#include "strclass.h"
// use folding to map a social security
// number into an integer in the
// range 0..2997
int hashf(char *ssn)
{
// declare s as a String object with value ssn
// and an objectg threeDigits that holds groups
// of three digits from ssn
String s = ssn, threeDigits;
int sum = 0, index = 0;
// extract and sum the three groups
for (int i=0;i < 3;i++)
{
// extract the current group of 3 digits. the
// groups start at indices 0, 3, 6
threeDigits = s.Substr(index,3);
index += 3;
// add the integer value of the string to sum
sum += atoi(threeDigits);
}
return sum;
}
void main(void)
{
cout << hashf("987543358") << endl;
}
/*
<Run>
1888
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -