ACM-字符串处理
文章平均质量分 67
LarryNLPIR
专注NLP/IR/Machine Learning/Data Mining
展开
-
POJ 2159 字符串加密
POJ 2159#include #include using namespace std; //此题算法不好想:将上下两行的字符根据出现次数进行排序,然后进行一一的比较,如果匹配的话即可,答案为YES,否则为NO //即无论怎样加密不会改变每个字母出现的频率 int compare(const void* a,const void* b){//const代表不改变参数值,void*值可以是任何类型的指针 return *(int *)a-*(int *)b;//取内容和强制类型转换原创 2010-11-12 21:21:00 · 1662 阅读 · 0 评论 -
LeetCode Restore IP Addresses
Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Order does not m原创 2015-02-23 10:01:11 · 1909 阅读 · 0 评论 -
LeetCode Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.思路分析:这题很简单,基本就是以第一个字符串为标准,同时扫描后面的字符串对应index 字符是否相同,找到最大的相同前缀。但是实现的时候还是要注意一些corner case,比如输入数组为空或者只包含一个字符串的情况。AC Co原创 2015-02-23 11:09:36 · 1755 阅读 · 0 评论 -
LeetCode Word Break
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, givens = "leetcode",dict = ["leet", "code"原创 2015-01-23 13:13:43 · 2533 阅读 · 0 评论 -
LeetCode Reverse Words in a String
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".思路分析:这题算法很简单,用一个栈就可以搞定。trick part见如下的说明What constitutes a word?A sequence of non原创 2015-01-23 14:30:34 · 1949 阅读 · 0 评论 -
LeetCode - Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For原创 2015-02-03 06:29:35 · 1981 阅读 · 1 评论 -
LeetCode Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) o原创 2015-02-05 13:44:50 · 1528 阅读 · 0 评论 -
LeetCode Word Break II
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.Return all such possible sentences.For example, given s = “catsanddo原创 2015-02-07 12:08:42 · 3780 阅读 · 0 评论 -
POJ 1565 Skew Binary pow函数使用
这题是水题,主要是用到了C++字符串和cmath中的pow函数。 最近可有点多,做POJ时间不够,还是要抓紧一些,尤其是动态规划、搜索题等要多练。#include #include #include using namespace std; int main(){ string s; while(1){ cin>>s; if (s == "0") break; long result = 0; int k = 1; string::i原创 2010-11-30 22:24:00 · 1745 阅读 · 0 评论 -
POJ 1298 字母加密 STL String的使用及审题重要性
这题很简单,但由于审题不清WA了很多次,太不应该Any non-alphabetical character should remain the same, and all alphabetical characters will be upper case.即只要不是字母就不变,如下写法错误if(*it == ' ' || *it == ',') continue;另外,对C++ String的使用中如何将空格也输入也是一个难点,getline不太好用,这里用了一个C的string作为中间量,借助C函原创 2010-11-26 17:06:00 · 1517 阅读 · 0 评论 -
POJ 1016 循环数 字符串处理与英文理解
这题挺简单,但是题目稍微有点长,基本没什么算法。#include #include using namespace std; string transfer(string s){ int num[10] = {0}; char res[80]; int i; int j = 0; for (i = 0 ; i 0 && num[i] = 10) { res[j++] = num[i]/10 + '0'; res[j++] = num[i]%10原创 2010-11-22 20:07:00 · 1599 阅读 · 0 评论 -
POJ 3094 字符串处理及空格输入
// 如何将空格符当做字符串一部分输入,应该用gets(string *) // gets(s)函数与scanf("%s:",&s) 及scanf("%s",s) 相似, // 但不完全相同,使用scanf("%s",&s);函数输入字符串时存在 // 一个问题,就是如果输入了空格会认为字符串结束,空格后的 // 字符将作为下一个输入项处理,但gets()函数将接收输入的整 // 个字符串直到遇到回车为止。 #include using namespace std; int main(){原创 2010-11-16 18:29:00 · 1546 阅读 · 0 评论 -
LeetCode Regular Expression Matching
Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input string原创 2015-02-15 13:33:55 · 2514 阅读 · 0 评论