⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wex14_18.cpp

📁 数据结构C++代码,经典代码,受益多多,希望大家多多支持
💻 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 + -