Python核心源代码:
if blkdat != []: # 黑名单过滤
if buildhit == 'Y':
fhitblk = file(mainpath + 'b_' + outputfile, 'wb')
outdat = []
print '排序黑名单...'
blkdat.sort()
print '过滤黑名单...'
hitnum = 0
for a in xrange(len(orgdat)):
b = bisect_left(blkdat, orgdat[a])
if b>=len(blkdat) or blkdat[b] != orgdat[a]:
outdat.append(orgdat[a])
else:
hitnum = hitnum + 1
if buildhit == 'Y':
fhitblk.write(orgdat[a] + '\r\n')
print '被黑名单过滤掉的号码总数为:', hitnum
if buildhit == 'Y':
fhitblk.close()
orgdat = outdat
C#核心源代码:
private void deal_Click(object sender, EventArgs e)
{
ArrayList org = new ArrayList();
ArrayList blk = new ArrayList();
StreamReader sr = new StreamReader(orgname);
StreamReader er = new StreamReader(blkname);
StreamWriter fr = new StreamWriter("left.txt");
string dat;
while ((dat = sr.ReadLine()) != null)
org.Add(dat.TrimEnd("\r\n".ToCharArray()));
while ((dat = er.ReadLine()) != null)
blk.Add(dat.TrimEnd("\r\n".ToCharArray()));
blk.Sort();
int orglen = org.Count;
for (int a = 0; a < orglen; a++)
{
if (blk.BinarySearch(org[a]) < 0)
fr.WriteLine(org[a]);
}
fr.Close();
MessageBox.Show("处理完毕!");
}