problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
lintcode::license_key_formatting::Solution类 参考

#include <lintcode.h>

静态 Public 成员函数

static string licenseKeyFormatting (string &, int)
 

详细描述

在文件 lintcode.h20 行定义.

成员函数说明

◆ licenseKeyFormatting()

string lintcode::license_key_formatting::Solution::licenseKeyFormatting ( string &  S,
int  K 
)
static
参数
Sa string
Ka integer
返回
: return a string

在文件 lintcode.cpp18 行定义.

18 {
19 auto S2 = ostringstream();
20 auto output = ostringstream();
21 int len = 0;
22 for(char c: S) {
23 if(isalnum(c) != 0) {
24 len++;
25 if(isdigit(c) != 0 || isupper(c) != 0) {
26 S2 << c;
27 } else if(islower(c) != 0) {
28 S2 << static_cast<char>(toupper(c));
29 }
30 }
31 }
32 string str = S2.str();
33 int first = len % K;
34 if(first == 0) {
35 first = K;
36 }
37 string str1 = str.substr(0, first);
38 string str2 = str.substr(first);
39 for(char c: str1) {
40 output << c;
41 }
42 int count = 0;
43 for(char c: str2) {
44 if(count == 0) {
45 output << '-';
46 }
47 output << c;
48 count++;
49 count %= K;
50 }
51 return output.str();
52 }

被这些函数引用 lintcode::license_key_formatting::TEST().


该类的文档由以下文件生成: