由买买提看人间百态

topics

全部话题 - 话题: newstr
1 (共1页)
m***2
发帖数: 595
1
贴块砖,感觉是我见到的最容易理解好记的版本了
而且能够过最新的test (好多解法之前能过,最新的容易Memory超,感觉leetcode的
判断更严格了)
public class Solution {
public List> findLadders(String start, String end, Set<
String> dict) {
List> result = new ArrayList>();
if (start == null || end == null || start.length() != end.length() |
| dict.size() == 0) {
return result;
}

HashMap> visited = new HashMap HashSet>();
... 阅读全帖
D*****d
发帖数: 1307
2
来自主题: Joke版 - 学术版求教一下
I wrote some java code, might be ugly, but it works...
package Testing;
public class TestReplaceWithQuotes {
public static String replaceInsideQuotes(String source, char quote,
String target, String replacement){
StringBuilder regex = new StringBuilder();
StringBuilder replace = new StringBuilder();

String quoteChar = Character.isDigit(quote) || Character.
isAlphabetic(quote) ? String.valueOf(quote) : ("\" + quote);
String nonQuoteChar = "[^" + quoteCh... 阅读全帖
f**********t
发帖数: 1001
3
来自主题: JobHunting版 - 问一个memory allocate/release的问题
I have this string s1 = "My name is X Y Z" and I want to reverse the order
of the words so that s1 = "Z Y X is name My".
我写出了算法,结果正确,但是最后一步memory release时出错:
int ReverseWords (char *str) {
if (!str || str == "")
return 0;
char *newstr = new char[strlen(str)];
int i = strlen(str) - 1;
int start, end, k = 0;
while (i >= 0) {
start = end = i;
while (start >= 0 && str[start] != ' ')
--start;
for (int j = start+1; j <= end; ++j)
... 阅读全帖
z********i
发帖数: 568
4
来自主题: Programming版 - C++ Segment Fault
char* newStr=function_call(...)
cout<<"newStr="< cout<<"newStr="<
S**I
发帖数: 15689
5
来自主题: JobHunting版 - HELP: C programming question
#include
#include
#include
struct StringCount{
char s[100];
int count;
};
int compare(const void * a, const void * b){
return ((*(struct StringCount *)a).count < (*(struct StringCount *)b).count);
}
void printSortedWords(char * s, FILE * file){
int size = strlen(s);
struct StringCount sc[100];
int num = 0;
char newstr[100];
int i = 0;
for(; i < size; i++){
if(s[i] != ' '){
int j = 0;
while(s[i]... 阅读全帖
x********i
发帖数: 92
6
来自主题: JobHunting版 - G家电面题
感觉对y的处理比较复杂. 我纯新手...写了一个代码, 望斧正
然后对于大小写的处理, 我就是创建一个新数组, 然后把所有的都转换成小写字母.
我运行了题目里给出的所有字符串, 结果都是正确的, 然后test了一个空字符串, 返回
为0. 求问还需要做什么样的test啊? 感觉很多代码写出来自己都不知道对不对, 因为
没有完善的test方案, 求指点...新手跪谢了
#define VOWELY 0
#define CONSOY 1
int vowelProduct(const char* newstr){
int length = strlen(newstr);
const char* consolant = "bcdfghjklmnpqrstvwxz";
const char* vowels = "aeiou";
int i;
int yFlag;
int score=0;
char* current;
char* yTest;
int point[26] = {0};
int tempScore=0;... 阅读全帖
i*c
发帖数: 1132
7
I found this elegant code using string.
string swtch(string topermute, int x, int y)
{
string newstring = topermute;
newstring[x] = newstring[y];
newstring[y] = topermute[x]; //avoids temp variable
return newstring;
}
void permute(string topermute, int place)
{
if(place == topermute.length() - 1)
{
cout< }
for(int nextchar = place; nextchar <
topermute.length(); nextchar++)
{
permute(swtch(topermute, place, nextchar),
j*****j
发帖数: 115
8
int start=0;
int idx=0;
foo(char* str, int M, int start,int idx, char* newStr)
{
if(idx==M){ newStrp[idx+1]='\0';cout< for(int i=start;i {
newStr[idx]=str[i];
foo(str,start+1,idx+1,newStr);
}
}
r*****t
发帖数: 68
9
my idea is to reassemble a string by moving certain number of chars from the
end to the head, and compare the new string with the old. if match, it
means the moved portion is the repeative portion. Can ignore the complexity
of string comparison?
int n=mInput.size()
if(n<=2)
return false;
string newstr(n, mInput[0]);//consist of unique char
if(mInput.compare(newstr)==0)
return false;
for i>=2 && i<=n/2)
{
if( (n-i)%i==0 )
{
//move last ith chars to the front
newstr=mInput.subs... 阅读全帖
r*****t
发帖数: 68
10
my idea is to reassemble a string by moving certain number of chars from the
end to the head, and compare the new string with the old. if match, it
means the moved portion is the repeative portion. Can ignore the complexity
of string comparison?
int n=mInput.size()
if(n<=2)
return false;
string newstr(n, mInput[0]);//consist of unique char
if(mInput.compare(newstr)==0)
return false;
for i>=2 && i<=n/2)
{
if( (n-i)%i==0 )
{
//move last ith chars to the front
newstr=mInput.subs... 阅读全帖
d****n
发帖数: 1637
11
来自主题: Programming版 - C++ Segment Fault
cout<<"newStr="newStr< == change to==>
cout<<"newStr="<
R*********i
发帖数: 7643
12
来自主题: Statistics版 - 菜鸟问题 (R & SAS)
A not-so-straightforward but working solution in SAS:
data test;
mystr='abcdef ghijklnopaijeiajig aeioajgeojgajipa aweg rrr eagaggeagg
awgae gawegwgaaag aewh aawgah';
newstr=compress(mystr);
l=length(newstr);
output;
run;
proc sql;
select left(put(ceil(l/10),4.)) into :len from test;
quit;
data test2;
length newvar1 - newvar&len $10;
set test;
array newvar [*] $ newvar1 - newvar&len;
do i=1 to dim(newvar);
newvar[i]=substr(newstr,1+10*(i-1),10);
end;
drop i newstr;
run... 阅读全帖
h**********d
发帖数: 4313
13
来自主题: JobHunting版 - AMAZON,GOOGLE 一面
这题我以前看过
String replaceString(String string, String oldString, String newString){
if(string == null || oldString == null || newString == null){
throw new IllegalArgumentException("Null arguments");
}
if(oldString.equals("")){
throw new IllegalArgumentException("oldString has no content");
}
StringBuilder result = new StringBuilder();
int i = 0;
int j = 0;
while((j = string.indexOf(oldString, i)) >= 0){
... 阅读全帖
n*s
发帖数: 752
14
来自主题: JobHunting版 - Epic Written Interview
4. string transpose
import sys
def transpose(input,i):
mystr = list(input)
mystr[i],mystr[i+1] = mystr[i+1],mystr[i]
return ''.join(mystr)
def str_transpose():
print 'input two strings, separated by blank:'
a, b = sys.stdin.readline().split()
size = len(a)
if size != len(b) or sorted(a) != sorted(b):
return 'no way!'
next = [b]
parent = {b:None}
idx = size -1
notFound = True
while notFound:
newstr = []
for x in next:
... 阅读全帖
n*s
发帖数: 752
15
来自主题: JobHunting版 - Epic Written Interview
4. string transpose
import sys
def transpose(input,i):
mystr = list(input)
mystr[i],mystr[i+1] = mystr[i+1],mystr[i]
return ''.join(mystr)
def str_transpose():
print 'input two strings, separated by blank:'
a, b = sys.stdin.readline().split()
size = len(a)
if size != len(b) or sorted(a) != sorted(b):
return 'no way!'
next = [b]
parent = {b:None}
idx = size -1
notFound = True
while notFound:
newstr = []
for x in next:
... 阅读全帖
s******n
发帖数: 3946
16
来自主题: JobHunting版 - 攒人品之facebook电面面经
觉得那个不太好,用share pointer:
class COWString {
share_ptr data;
public:
COWString(const char* input)
{
data = share_ptr(new CString(input));
}
COWString(const COWString& str)
{
data = str.data;
}
COWString& operator=(const COWString& str)
{
data = str.data;
return *this;
}
COWString& SetAt(int index, char c)
{
CString* newStr = new CString(data->c_str());
newStr->SetAt(index, c);
data = share_ptr(newStr);
return *this;
}
char GetAt(int index) const
{
... 阅读全帖
s******n
发帖数: 3946
17
来自主题: JobHunting版 - 攒人品之facebook电面面经
觉得那个不太好,用share pointer:
class COWString {
share_ptr data;
public:
COWString(const char* input)
{
data = share_ptr(new CString(input));
}
COWString(const COWString& str)
{
data = str.data;
}
COWString& operator=(const COWString& str)
{
data = str.data;
return *this;
}
COWString& SetAt(int index, char c)
{
CString* newStr = new CString(data->c_str());
newStr->SetAt(index, c);
data = share_ptr(newStr);
return *this;
}
char GetAt(int index) const
{
... 阅读全帖
f*******n
发帖数: 12623
18
来自主题: JobHunting版 - 问一个memory allocate/release的问题
你是这里出错:
char *newstr = new char[strlen(str)];
...
newstr[k] = '\0';
strcpy(str, newstr);
f*****2
发帖数: 141
19
麻烦大家帮我看看哪有错误,为什么老师运行时候有错误?非常感谢!
void remove_duplicate_value(char* str)
{
int i, j, len;
char *newStr;
len = strlen(str);
for (i = 1; i < len; i++)
{
for (j = i-1; j >= 0; j--)
{
if (str[i] == str[j])
{
int k = i+1;
while (str[i] == str[k] && k <= len)
{
k++;
}
if (str[i] != str[k])
str[i] = str[k];
else... 阅读全帖
r******r
发帖数: 700
20
来自主题: JobHunting版 - 谁能猜猜,这是个什么 algorithm?
Complexity 是多少? 别运行,试试看。
public static void mysteriousAlgorithm(String st, String chars) {
if (chars.length() == 1)
System.out.println(st + "" + chars);
else
for (int i = 0; i < chars.length(); i++) {
String newString = chars.substring(0, i) + chars.
substring(i + 1);
mysteriousAlgorithm(st + chars.charAt(i), newString);

}
}
a*f
发帖数: 1790
21
来自主题: Programming版 - FP才是真正的主流,比如Excel
Haskell可以写FP,但是不等于Haskell代码都是FP
下面这段代码定义Web form的一个field,都是描述性的定义,看不出和FP有啥关系,
按这种方式写Web有啥好处?
import Html exposing (Html, Attribute, text, toElement, div, input)
import Html.Attributes exposing (..)
import Html.Events exposing (on, targetValue)
import Signal exposing (Address)
import StartApp.Simple as StartApp
main =
StartApp.start { model = "", view = view, update = update }
update newStr oldStr =
newStr
view : Address String -> String -> Html
view address string =
div []
[ input
... 阅读全帖
c*****e
发帖数: 32
22
来自主题: Unix版 - bourne shell program Question

newstring=${name%.*}
the newstring 的值是你想要的。
f**********t
发帖数: 1001
23
来自主题: JobHunting版 - 问一个memory allocate/release的问题
嗯,发现了。
因为strlen(str)没有算'\0',比如strlen("abc") = 3.
这样的话newstr的长度就比str少1,而不是相等。
A***o
发帖数: 358
24
newStr 没初始化
a*m
发帖数: 6253
25
来自主题: Tennis版 - Free string promotions
www.wilson.com/newstring
for wilson hollow core.
e*i
发帖数: 3
26
来自主题: Java版 - 问高手:数字签名
问高手:RSA+md5数字签名后的数据转换成二进制数组byte[],如何转成string类型(
规范中规定必须是String类型)
后又转换回byte[](因为验证签名verify()的参数是byte[]),我试了很多办法后来的返
回的字节数组都与原来的不同,无论是newstring的IS01889-1,还是BASE64,HexDumpEn
coder编码,
原因仿佛是RSA加密的二进制数据是DER编码的PCK#5填充块,很多转换方式都会丢失二进
制数据,
我不知道应该用什么转换编码了,请帮忙。
w***y
发帖数: 6251
27
来自主题: Java版 - 问个String:replaceALL的问题
如果我想把字符串中的' 换成\', 怎么处理呢?
我试了String newstr=str.replaceAll("'","\\'");
不行,'还是',没替换成\'
单独输出\用\\可以,不知道为啥后面加个'就不行了
B**z
发帖数: 153
28
sed 's/oldstring/newstring/g' oldfile > newfile
f****n
发帖数: 4615
29
来自主题: Unix版 - UNIX command to
vi: 进入command状态, vi左下角出现“:”
<:>oldstringnewstring
其中的 <> 是为了方便阅读用的, 实际操作时去掉。
s****s
发帖数: 8
30
来自主题: Unix版 - UNIX command to

an alternative way: :%s/oldstring/newstring/g
the
e****e
发帖数: 179
31
来自主题: Unix版 - question about sed
when I use sed to replace a string in a file, it only shows on the screen that
string has been changed, but when I open that file, it is still the same as
before.
the command I used is:
sed -e 's,oldstr,newstr,' filename
thanks.
c******r
发帖数: 38
32
来自主题: Unix版 - question about sed
You need output it to another file like:
sed -e 's,oldstr,newstr,' filename >filename1
s**s
发帖数: 242
33
用shell和sed:
for fn in *.c
do
cat $fn |sed -e 's/oldstr/newstr/' >tmp.$fn
mv tmp.$fn $fn
done
l****u
发帖数: 529
34
data yourdata;
set yourdata;
do i=1 to count(yourstr,',')+1;
newstring=scan(yourstr,i,',');
output;
end;
run;
1 (共1页)