来自http://www.geeksforgeeks.org/amazon-interview-set-89/
我们有n个金币.我们需要将所有n个硬币合并为一个硬币,我们可以同时合并两个硬币.合并两个硬币的成本等于这些硬币的价值.我们如何确保合并n个硬币的成本最低.
Run Code Online (Sandbox Code Playgroud)Ex: 5 ,8 , 4, 3, 9, 6 We will merge 3 and 4, cost=7 {Remaining coins: 5,8,9, 6,7} Then we merge 5 and 6, cost=11 { Remaining coins: 11,8,9,7} Then we merge 7 and 8, cost=15 { Remaining coins: 11,15,9} Then we merge 9 and 11, cost=20 { Remaining coins: 20,15} Then we merge 20 and 15, cost=35 { Remaining coins: 35} Total cost: 7+11+15+20+35 = 88如果我们以不同的方式合并了硬币阵列{5,8,4,3,9,6}:
Run Code Online (Sandbox Code Playgroud)Merging 5 and 8, cost=13 {Remaining coins: 13, …
给定一个字符串数组,我需要找出其中的字符串数.
我跟着这个
但如果我将其传递给函数,这不起作用.
这是我试过的代码
#include<string>
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int f1(char* input1[])
{
string s="";
cout<<sizeof(input1)<<endl; //print 4
cout<<sizeof(char*)<<endl; //print 4
int l=sizeof(input1) / sizeof(char*);
//giving l=1 here but should be 8
}
int main()
{
char *str2[]={"baba","sf","dfvf","fbfebgergrg","afvdfvfv","we","kkhhff","L"};
int l=sizeof(str2) / sizeof(char*);
cout<<l<<endl; //print 8
cout<<sizeof(str2)<<endl; //print 32
cout<<sizeof(char*)<<endl; //print 4
f1(str2);
}
Run Code Online (Sandbox Code Playgroud) 我想从angellist https://angel.co/companies获取公司列表
我试过这个代码
from bs4 import BeautifulSoup
import urllib2
headers = { 'User-Agent' : 'Mozilla/5.0' }
req = urllib2.Request('https://angel.co/companies', None, headers)
html = urllib2.urlopen(req).read()
soup = BeautifulSoup(html, "html.parser")
p1 = soup.find_all('div' , {"class"," dc59 frw44 _a _jm"})
print p1
Run Code Online (Sandbox Code Playgroud)
但是这会返回一个空字符串.
我曾经历过类似的问题,有人说更新beautifulsoup,有人说改变解析器.没有什么对我有用.
I need to parse both var & group root elements.
Code
import xml.etree.ElementTree as ET
tree_ownCloud = ET.parse('0020-syslog_rules.xml')
root = tree_ownCloud.getroot()
Run Code Online (Sandbox Code Playgroud)
Error
xml.etree.ElementTree.ParseError: junk after document element: line 17, column 0
Sample XML
<var name="BAD_WORDS">core_dumped|failure|error|attack| bad |illegal |denied|refused|unauthorized|fatal|failed|Segmentation Fault|Corrupted</var>
<group name="syslog,errors,">
<rule id="1001" level="2">
<match>^Couldn't open /etc/securetty</match>
<description>File missing. Root access unrestricted.</description>
<group>pci_dss_10.2.4,gpg13_4.1,</group>
</rule>
<rule id="1002" level="2">
<match>$BAD_WORDS</match>
<options>alert_by_email</options>
<description>Unknown problem somewhere in the system.</description>
<group>gpg13_4.3,</group>
</rule>
</group>
Run Code Online (Sandbox Code Playgroud)
I tried following couple of other questions on stackoverflow here, but …
谁可以告诉我的步骤将Google共享幻灯片就像这对杰基尔我的博客?我是否必须将每个幻灯片转换为markdown格式,或者先转换为pdf,然后转换为markdown?
没头绪 请帮忙
我有一个像这样的python str对象,我想将其转换为列表
l = "['Incorrect password.$', 'Login failed']" --- type <str>
Run Code Online (Sandbox Code Playgroud)
预期产出
l = ['Incorrect password.$', 'Login failed'] ---- type <list>
Run Code Online (Sandbox Code Playgroud)
试验1:
p = list(l)
Run Code Online (Sandbox Code Playgroud)
这让l作为['[', "'", 'I', 'n', 'c', 'o', 'r', 'r', 'e', 'c', 't', ' ', 'p', 'a', 's', 's', 'w', 'o', 'r', 'd', '.', '$', "'", ',', ' ', "'", 'L', 'o', 'g', 'i', 'n', ' ', 'f', 'a', 'i', 'l', 'e', 'd', "'", ']']
试验2:
l.split(',')
Run Code Online (Sandbox Code Playgroud)
第二种方法是不利的,因为列表元素本身可能包含逗号.
我该怎么办?任何提示都表示赞赏.