[CareerCup] 17.14 Unconcatenate Words 断词

17.14 Oh, no! You have just completed a lengthy document when you have an unfortunate Find/Replace mishap. You have accidentally removed all spaces, punctuation, and capitalization in the document. A sentence like "I reset the computer. It still didn‘t boot!" would become "iresetthecomputeritstilldidntboot". You figure that you can add back in the punctation and capitalization later, once you get the individual words properly separated. Most of the words will be in a dictionary, but some strings, like proper names, will not.

Given a dictionary (a list of words), design an algorithm to find the optimal way of "unconcatenating" a sequence of words. In this case, "optimal" is defined to be the parsing which minimizes the number of unrecognized sequences of characters.

For example, the string "jesslookedjustliketimherbrother" would be optimally parsed as "JESS looked just like TIM her brother". This parsing has seven unrecognized characters, which we have capitalized for clarity.

时间: 2024-10-19 22:34:10

[CareerCup] 17.14 Unconcatenate Words 断词的相关文章

[CareerCup] 17.1 Swap Number In Place 互换位置

17.1 Write a function to swap a number in place (that is, without temporary variables). 这道题让我们交换两个数,但是不能用额外空间,那么我们可以先做差值,存入a中,然后再加上b,存入b中,那么此时的b即为原来的a,因为整个相当于做了一个a - b + b的过程,那么现在b是原来的a,而a中现在保存的是差值,,那么原来的b值就可以通过b-a来得到,保存到a中即可: 解法一: void swap(int a, i

[CareerCup] 17.8 Contiguous Sequence with Largest Sum 连续子序列之和最大

17.8 You are given an array of integers (both positive and negative). Find the contiguous sequence with the largest sum. Return the sum. LeetCode上的原题,请参见我之前的博客Maximum Subarray. 解法一: int get_max_sum(vector<int> nums) { int res = INT_MIN, sum = INT_MI

[CareerCup] 17.9 Word Frequency in a Book 书中单词频率

17.9 Design a method to find the frequency of occurrences of any given word in a book. 这道题让我们找书中单词出现的频率,那么首先需要搞清楚的问题是,只需要统计一个单词,还是多个单词.如果是一个单词的话,那直接就遍历所有单词直接统计即可,如果是多个,就需要建立哈希表来建立每个单词和其出现次数之间的映射,然后再来查找即可,参见代码如下: unordered_map<string, int> make_dicti

[CareerCup] 17.10 Encode XML 编码XML

17.10 Since XML is very verbose, you are given a way of encoding it where each tag gets mapped to a pre-defined integer value. The language/grammar is as follows: Element --> Tag Attributes END Children END Attribute --> Tag Value END --> 0 Tag -

[CareerCup] 17.2 Tic Tac Toe 井字棋游戏

17.2 Design an algorithm to figure out if someone has won a game oftic-tac-toe. 这道题让我们判断玩家是否能赢井字棋游戏,有下面几点需要考虑: 1. 判断是否能赢hasWon函数是调用一次还是多次,如果是多次,我们可能为了优化而需要加入一些预处理. 2. 井字棋游戏通常是3x3的大小,我们是否想要实现NxN的大小? 3. 我们需要在代码紧凑,执行速度和代码清晰之间做出选择. #include <iostream> #

css控制换行,断词

word-break 属性规定自动换行的处理方法. word-break:normal | break-all | keep-all; normal:使用浏览器默认的换行规则. break-all:允许在单词内折行. keep-all:只能在半角空格或连字符处换行. <div style="word-break: break-all;">JavaScript,一種直譯式程式語言, 是一种动态类型.弱类型.基于原型的语言,内置支持類別.它的直譯器被稱為JavaScript引擎

[CareerCup] 17.6 Sort Array 排列数组

17.6 Given an array of integers, write a method to find indices m and n such that if you sorted elements m through n, the entire array would be sorted. Minimize n - m (that is, find the smallest such sequence).

day 17 文件操作17:14 -17:43

import _import_ 以字符串形式导入 # f=open('陈粒',encoding='utf-8')# data=f.read()# print(data)# f.close()//默认是读取r模式,只能读取 f.readable() 是否可读取 data=f.readlines()一次读取一行print(data)f.close() 原文地址:https://www.cnblogs.com/yikedashuyikexiaocao/p/9205015.html

CareerCup All in One 题目汇总

Chapter 1. Arrays and Strings 1.1 Unique Characters of a String 1.2 Reverse String 1.3 Permutation String 1.4 Replace Spaces 1.5 Compress String 1.6 Rotate Image 1.7 Set Matrix Zeroes 1.8 String Rotation Chapter 2. Linked Lists 2.1 Remove Duplicates