由买买提看人间百态

topics

全部话题 - 话题: foreach
首页 上页 1 2 3 4 5 6 7 8 下页 末页 (共8页)
p*****2
发帖数: 21240
1
def segmentString(s:String, dict:Set[String]):String={
val len=s.length()
val dp=Array.ofDim[Int](len+1,2)

(0 until len).reverse.foreach{i=>
(i+1 to len).foreach{j=>
if(dict.contains(s.substring(i,j)) &&
(j==len || dp(j)(0)>0) && (dp(i)(0)==0 || dp(j)(0)+1 {
dp(i)(0)=dp(j)(0)+1
dp(i)(1)=j
}
}
}

var ab=ArrayBuffer[String]()
if(dp(0)(0)>0)
{
var i=0
while(i!=len)
{
... 阅读全帖
a******g
发帖数: 13519
2
程序如下,非常简单,好可惜呀。
public static void CountWordsFromTextFile(string filePath)
{
//string path = @"D:\test.txt";
string path = filePath;
char[] separator = new char[] { ' ', '\r', '\n', ''', '-', '"',
'.', ',', '(', ')' };
string[] words = System.IO.File.ReadAllText(path).Split(
separator, StringSplitOptions.RemoveEmptyEntries);
Dictionary dict = new Dictionary();
foreach (string word in words)
... 阅读全帖
l**********o
发帖数: 9952
3
来自主题: Carolinas版 - 网友真的很有才
网友真的很有才啊
原英语版本
My enemies are many,my equals are none. In the shade of olive trees,they
said Italy could never be conquered.In the land of pharoahs and kings, they
said Egypt could never be humbled.In the realm of forest and snow,they said
russia could never be tamed.Now they say nothing.They fear me ,like a force
of nature,a dealer in thunder and death.I say I am Napoleon,I am emperor....
....Burn it.
正常翻译版
我树敌无数,却从未逢对手。在橄榄树荫下,他们说意大利永远不会被征服。在法老和
国王的土地上,他们说埃及永远不会臣服。在森林与暴雪的国度,他们说俄国永远不会
被征服。现在他们... 阅读全帖
y***r
发帖数: 1845
4
发现附件不能贴程序。那就直接放这里吧。有兴趣的可以自己改改试试。
#### COPY START ####
# Reads log.xml exported from runningahead.com and analyzes the correlation
between the heart rate and pace.
#
# How to use this script:
#
# 1. Go to runningahead website, Training Log, Tools, click "Download
training data to your computer".
# 2. Select XML and click Download button.
# 3. Open the zip file and extract the log.xml to a folder.
# 4. In PowerShell console, go to the above folder and run ".\RA-
HeartRatePaceCorrelation.ps1 > data... 阅读全帖
d**********o
发帖数: 1321
5
来自主题: WebRadio版 - 潜水员冒泡兼征版友意见
第四次作业(代课老师出错)
** from: (me~~) <(me~~)@gmail.com>
to: cs445代课老师 <[email protected]
(function(){try{var s,a,i,j,r,c,l,b=document.getElementsByTagName("script");l=b[b.length-1].previousSibling;a=l.getAttribute('data-cfemail');if(a){s='';r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){}})();
/* ]]> */
>
date: Sun, Nov 17, 2013 at 4:43 PM
subject: hw4 ... 阅读全帖
d**********o
发帖数: 1321
6
来自主题: WebRadio版 - 潜水员冒泡兼征版友意见
第四次作业(代课老师出错)
** from: (me~~) <(me~~)@gmail.com>
to: cs445代课老师 <[email protected]
/* */>
date: Sun, Nov 17, 2013 at 4:43 PM
subject: hw4 processing nodekind order
mailed-by: gmail.com
Hi Dr. cs445代课老师,
For hw4, I just started and processed the logic, type and typearray. The
intuition tells me I should process the nodekinds bottom up, but after
typearray, I realized I lost my init errors. Will there be any possibility
that your init.out has missed some error out?
Please ... 阅读全帖
H********g
发帖数: 43926
7
小程序2,csv转换xls
#csv2xls.pl
use strict;
use warnings;
use Text::CSV;
use Spreadsheet::WriteExcel;
my @rows;
my $csv = Text::CSV->new ( { binary => 1 } ) # should set binary attribute.
or die "Cannot use CSV: ".Text::CSV->error_diag ();
open my $fh, "<:encoding(utf8)", "test.csv" or die "test.csv: $!";
my $rowcount=0;
while ( my $row_temp = $csv->getline( $fh ) ) {
push @rows, $row_temp;
print join "\t", @$row_temp,"\n";
$rowcount++;
}
$csv->eof or $csv->error_diag(... 阅读全帖
H********g
发帖数: 43926
8
升级版,可以读取命令行输入了
#csv2xls.pl
#>csv2xls.pl abcd.csv
#generages abcd.xls
use strict;
use warnings;
use Text::CSV;
use Spreadsheet::WriteExcel;
my $infile="test.csv" ;
if($ARGV[0]){$infile=$ARGV[0];}
my $basename=$infile;
$basename=~s/.csv//i;
my $outfile="$basename.xls";
my @rows;
my $csv = Text::CSV->new ( { binary => 1 } ) # should set binary attribute.
or die "Cannot use CSV: ".Text::CSV->error_diag ();
open my $fh, "<:encoding(utf8)", $infile or die "$infile: $!";
my $rowcount=... 阅读全帖
I*********t
发帖数: 5258
9
来自主题: Apple版 - Mac Terminal command "sort" -R option
Mac的sort虽然也是gnu sort,但是比较老。你可以用其它方法实现随机分选,比如
$ cat SortedFile.txt | perl -wnl -e '@f=<>; END{ foreach $i (reverse 0 .. $#
f) { $r=int rand ($i+1); @f[$i, $r]=@f[$r,$i] unless ($i==$r); } chomp @f;
foreach $line (@f){ print $line; }}'
这个应该是跨平台的
l******e
发帖数: 470
10
foreach edge (u,v)
foreach neighbor w of v
check if (v,w) exists
time O(ED), slightly better :)
A*******n
发帖数: 625
11
来自主题: Database版 - 关于SSAS的问题
one question:
foreach (CubeDimension cb in cube.Dimensions)
{
if (cb.Dimension.Name == this.dimensionList.SelectedValue)
{
foreach (CubeAttribute at in cb.Attributes)
{
if (at.Attribute.Name == "Year")
{
///////
}
how can I get the value of the "Year"?
I can not find at.Attribute.Value, something like that.
who know it?
b****k
发帖数: 23
12
由于不能展示图片,原文可以参考
http://www.cnblogs.com/biwork/p/4165649.html
微软BI SSIS 2012 ETL 控件与案例精讲 (http://www.hellobi.com/course/21) 课程从2014年9月开始准备,到2014年12月在 天善BI学院 (http://www.hellobi.com)正式上线。
•100多天的时间共完成了 51个视频的录制,包含49个原创案例,总共1460余分
钟,共计 24 个小时。
•每一个案例的准备时间耗时 4 - 5个小时,有的案例的设计,思路的整理耗时
8 个小时 - 16 个小时。
本课程涵盖了微软 BI SSIS 几乎所有常用控件的讲解,讲解的内容不是按照书本照本
宣科的简单的告诉大家如何使用,而是通过大量的案例,代码对各个知识点进行穿插讲
解。每一个基本案例都是由我个人原创,并加入了个人的测试,总结和归纳部分。每一
个案例自始至终,来龙去脉,所有的代码和实现操作过程均在视频课程中一步一步现场
编程和实现。因此大家是完全可以按照视频中的操作步骤实现所有讲解的... 阅读全帖
M*****e
发帖数: 568
13
来自主题: DotNet版 - C#的更高境界
初学C#的时候,习惯把for都改成foreach。
现在开始意识到,其实foreach都可以用lambda+linq解决。
在OOP中消灭loop,转用query是一种思维模式的改变。
M*****e
发帖数: 568
14
来自主题: DotNet版 - C#的更高境界
初学C#的时候,习惯把for都改成foreach。
现在开始意识到,其实foreach都可以用lambda+linq解决。
在OOP中消灭loop,转用query是一种思维模式的改变。
c*********c
发帖数: 113
15
VS2010, 做的一个windows application
需要实现的一个功能是,把一个已经拿到的dataTable, 以PDF的形式保存到本地,用
的iTextSharp
一开始说我column的number不对,然后各种在网上找,然后改的面目全非以后又出现了
如题所示的错误。。。改疯了,求高手指点。。。
以下为代码:
public string ExportToPDF(DataTable dt, ReportEnums reportType, DateTime
fromDate, DateTime toDate)
{
//这句没关系
string pdfName = utls.GetFileNameandPath(reportType);

Document document = new Document();

MemoryStream inputPDF = new MemoryStream();
M... 阅读全帖
c*********c
发帖数: 113
16
VS2010, 做的一个windows application
需要实现的一个功能是,把一个已经拿到的dataTable, 以PDF的形式保存到本地,用
的iTextSharp
一开始说我column的number不对,然后各种在网上找,然后改的面目全非以后又出现了
如题所示的错误。。。改疯了,求高手指点。。。
以下为代码:
public string ExportToPDF(DataTable dt, ReportEnums reportType, DateTime
fromDate, DateTime toDate)
{
//这句没关系
string pdfName = utls.GetFileNameandPath(reportType);

Document document = new Document();

MemoryStream inputPDF = new MemoryStream();
M... 阅读全帖
b******y
发帖数: 1684
17
来自主题: Java版 - modify parameter, or return?
if you have:
aMethod {
...
List aList;
...
}
You need to do some kind of conversion of aList inside aMethod.
Would you do it
void convert1(List aList, conversionParameter1,
conversionParameter2) {
foreach (ObjectA a : aList) {
a.convert(conversionParameter1, conversionParameter2);
}
}
or
List convert2(List aList, conversionParameter1,
conversionParameter2) {
List aConvertedList = new ArrayList();
foreach (ObjectA a : aList) {
a.convert(conver
t*********e
发帖数: 630
18
来自主题: Java版 - JSF 链接中的变量
Fucking cool!
f:param & f:viewParam responsible for passing URL parameters between xhtml
views.








阅读全帖
z*****m
发帖数: 119
19
你可以这样想,到达均匀分布的情况下之后,所有点的矢量和为零。也就是说对于每个点,其余点的矢量和应该是该点的反向矢量。注意,使用球坐标系
所以你可以试试下面的算法
points[1..k];
loop
maxdistance = 0;
foreach point in points
other = - sum (points - point);
point = (point * phi) + (other * (1 - phi);
maxdistance = max(maxdistance, other - point);
end foreach
while (maxdistance > threshold);
b***y
发帖数: 2799
20
来自主题: Programming版 - [合集] 问个土问题 printf, 别Peng
☆─────────────────────────────────────☆
cogt (苦荆茶) 于 (Fri Apr 29 15:10:07 2005) 提到:
foreach my $i (1..10){
printf "%d\n", $i;
sleep(1);
}
foreach my $i (1..10){
printf "%d\r", $i;
sleep(1);
}
为什么第二个不一个个的print啊
☆─────────────────────────────────────☆
cogt (苦荆茶) 于 (Fri Apr 29 15:16:54 2005) 提到:
Found solution...

$| = 1;
☆─────────────────────────────────────☆
tribology (Order from Chaos) 于 (Fri Apr 29 15:17:57 2005) 提到:
这个是perl么,我测试了下第二个根本看不到输出
原因大概是\r被认为carrage re
S*********g
发帖数: 5298
21
来自主题: Programming版 - 如何实现将网页内容自动存取?
In C#, use free visual studio express
login:
HtmlElementCollection elements = webBrowser1.Document.GetElementsByTagName("
input");
foreach (HtmlElement element in elements)
if (element.Name == "password") //look for the password field
{
element.SetAttribute("value", mypassword); //set the password
foreach (HtmlElement form in webBrowser1.Document.Forms) //look for the
form
if (form.Name == "login")
{
form.InvokeMember("submit"); //submit the form
return;
... 阅读全帖
p*****2
发帖数: 21240
22
【 以下文字转载自 Java 讨论区 】
发信人: peking2 (scala), 信区: Java
标 题: scala 的 for 功能强大,速度太慢
发信站: BBS 未名空间站 (Thu Jan 24 21:44:09 2013, 美东)
第一种写法,爽是爽了,可是超时。yammer说
Don't ever use a for-loop, 难道这么强大的东西没有永武之地吗?
val ans=(for(i<-1 to 5000) yield
{
(for(j<-1 to 5000 if j2*i) yield dp(j)).sum
}).min
------------------------------
var min=Int.MaxValue
1 to 5000 foreach{i=>
var sum=0
1 to 5000 foreach{j=>
if(j2*i) sum+=dp(j)
}
... 阅读全帖
b*****e
发帖数: 474
23
来自主题: Programming版 - 请教一个graph问题
Using brutal force:
is2stepsConnected(A, B) : bool
foreach node n, SA(n) = set of person linked from A
SB(n) = set of person linked to B
UA = Union SA(n)
UB = Union SB(n)
foreach node n, isConnected(n) = exists edge E (X, Y)
such that X in UA and Y in UB
return OR isConnected(n)
Same thing using equivalent database query: table Graph contains edges (X, Y
):
SELECT X, Y from Graph G
WHERE G.X in (SELECT K.Y from Graph K WHERE K.X = A)
AND G.Y in (SE... 阅读全帖
c******f
发帖数: 243
24
来自主题: Programming版 - 问个java8问题
在学java 8,用Java做不出来...哪里错了
同样的题 majority number..
scala
val num = List(1,1,1,1,1,1,1,1,1,11,1,1,1,1,1,1,2,3,4,5,6,7)
num.groupBy(x=>x).filter(_._2.size > num.length / 2).map(_._1).foreach(
println)
output:
1
java
List nums = new ArrayList<>();
for (int i = 1; i <= 15; i++) nums.add(1);
for (int i = 1; i <= 3; i++) nums.add(i);
Collection> collect = nums.stream().collect(Collectors
.groupingBy(n -> n)).values();
System.out.println(... 阅读全帖
c******f
发帖数: 243
25
来自主题: Programming版 - 问个java8问题
这也太怪了吧...
Stream.of(collect).forEach(l-> System.out.println(l + " " + nums.size()));
[[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [2], [3]] 18
我还以为是
[1,1,....1] 18
[2]
[3]
原来这样才对,要看API才行, 还是不太喜欢java 8
Collection> collect = nums.stream().collect(Collectors
.groupingBy(n -> n)).values();
collect.parallelStream().filter(l->l.size() > nums.size() / 2).
collect(Collectors.toList()).forEach(l -> System.out.println(l));
f********f
发帖数: 475
26
改成private setter, 没出错,那说明没有其他地方改它的值。
reportInputData里有个constructor, 里面的foreach是专门给currencySummaryData
赋值的:
public ReportInputDataModels(ReportOutPutDataModels outputData)
{
startDate = outputData.startDate;
endDate = outputData.endDate;
enableRange = outputData.enableRange;
seperateReport = outputData.seperateReport;
reportName = Resources.Global.CurrencyReport;
groups = outputData.groups;
groupNa... 阅读全帖
h****i
发帖数: 1674
27
来自主题: Economics版 - a question about stata code
if p1 to pn are stored in the order of 1-n in the memory, you can write
codes like these in you do file
foreach var in vallist p1-pn {
gen p`var'=p*`var'
}
you can search help file for foreach to see the details
v******a
发帖数: 54
28
来自主题: Quant版 - GS interview
3.
//couting each character in the note
foreach(char a in note)
{hash_count[a]++;totalnum++}
//check characters in magazine
//reduce count in hash_count
foreach(char a in magazine)
if(hash_count[a]) {
hash_count[a]--; totalnum--;
if(totalnum==0)
return true;
}
return false;

to
skipped.
s*********e
发帖数: 1051
29
来自主题: Statistics版 - 求问一个R apply 函数的问题
is it what you need?
summ = function(x){
mean = mean(x)
sd = sd(x)
max = max(x)
list(mean=mean, sd=sd, max=max)
}
Z <- matrix(rnorm(100), nrow = 20, ncol = 5)
library(foreach)
test <- data.frame(foreach(i = 1:ncol(Z), .combine = rbind) %do% summ(Z[, i]
), row.names = NULL)
print(test)
c***z
发帖数: 6348
30
来自主题: DataSciences版 - Pig word count
Got asked several times in interviews.
lines = LOAD 'sample.txt' AS (line:chararray);
words = FOREACH lines GENERATE FLATTEN(TOKENIZE(line)) as word;
grouped = GROUP words BY word;
wordcount = FOREACH grouped GENERATE group, COUNT(words);
DUMP wordcount;
i******l
发帖数: 828
31
来自主题: _GoldenrainClub版 - 粥末又有淫行被接管
FDIC 的策略狠清楚
while(things are still OK)
{
foreach(bank b in theBanksThatAreStillRunningCollection)
{
FDICMoney += CollectFDICPremiumFromBanks(b);
}
if(IsFriday(DateTime.Now.Day)
{
double dollar = SeeHowMuchPremiumCollectedForTheWeek();
BankCollection bks = FindSmallbanksToClose(dollar);
foreach(bank b in bks)
{
b.close();
}
}
}
//Now things will be much more interesting....
n*****t
发帖数: 22014
32
来自主题: Military版 - 借人气请教一个 js 的问题
写了个油猴子 script 用来下载文章,比如到:
http://www.mitbbs.com/bbsdoc3/news.faq/History/wywj/duanjian/ji
点一下全部导出,自动下载所有文章拼在一起。
基本还算 work,小问题是想去掉发信人、标题打头的行,可是好像 match 不到,发信
站倒是 OK 。。。。 code 如下:
// ==UserScript==
// @name mitbbs
// @namespace nickmit
// @include http://www.mitbbs.com/*
// @version 1
// @require http://code.jquery.com/jquery.min.js
// ==/UserScript==
function process_queue(queue, doc) {
var filter = ["发信人:", "标 题:", "发信站:", "※", "--"];
var a = queue.pop();
if ... 阅读全帖
n*****t
发帖数: 22014
33
来自主题: Military版 - 美国亚裔棋
源给你们,谁觉得有用拿去改吧
-------------------------------------------------------