找出一个锯齿数组里长度大于5的子数组
在符合要求的子数组里的数据里找出所有偶数
如果数据小于10的话乘以2,大于10的除以2
最后统计符合要求的数据的和
#题目要求:https://gist.github.com/2227226/b133a8833acbdc37a48e5fc7d91ad56bb5b8729d | |
def RemoveMultipleSpaces(baseStr): | |
findSpace, count, space = False, 0, ' ' | |
for i, ch in enumerate(baseStr): | |
if findSpace and ch == space: continue | |
findSpace = ch == space | |
baseStr[count] = ch | |
count = count + 1 |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace LaozhaoQ | |
{ | |
// Please write an sequence list implements the interface with the required | |
// time complexity described in the comments. The users can add the same | |
// element as many times as they want, but it doesn't support the null item. |
def get_http_status(ip, port, host, path='/',ssl=False): | |
''' | |
根据指定IP,端口等信息返回该服务器的http状态,应答码,错误原因,响应时间 | |
代码写的很难看,求重构 | |
''' | |
newstatus, status_code, status_desc = config.Unknow, -99, '未知状态' | |
starttime = datetime.now() | |
try: | |
status_code = int(http((ip, port),host, path, ssl)) |
.section { | |
background-color:#eee; | |
padding:10px; | |
margin:10px; | |
width:600px; | |
clear:both; | |
overflow:hidden; | |
} | |
.w100 { | |
width:100px; |
static void Main(string[] args) | |
{ | |
if (args.Length != 2) return; | |
string searchPattern = args[0], dir = Path.GetDirectoryName(args[1]), filePattern = Path.GetFileName(args[1]); | |
var files = from file in Directory.EnumerateFiles(dir, filePattern, SearchOption.AllDirectories) | |
from line in File.ReadLines(file).Select((text, i) => new { Text = text, Index = i }) | |
where new Regex(searchPattern).IsMatch(line.Text) | |
select new { File = file, LineText = line.Text, LineNo = line.Index }; | |
Parallel.ForEach(files, (f) => { Console.WriteLine("{0}({1}){2}", f.File, f.LineNo, f.LineText); }); | |
} |
/* | |
紧凑版的grep,相对于对象健身操的实现,这段代码只是原版本的三分之一,个人感觉可读性也不是太差。 | |
原文地址:https://gist.github.com/1738383 | |
*/ | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text.RegularExpressions; | |
using System.IO; | |
using System.Threading.Tasks; |
/* | |
## 对象健身操 | |
http://www.infoq.com/cn/minibooks/thoughtworks-anthology | |
###规范 | |
1. 方法只使用一级缩进。 | |
1. 全部符合要求 | |
1. 大部分通过方法提取做到,有的带yield的语句块不好提取,幸好一些Linq方法可以用来抽象一些集合操作。 | |
1. 所有方法都尽量控制在5行以内,不包含空行和括号单独占的行 |
基本体系结构 | |
这个系统设计有三个独立进程。输入进程,控制进程,和输出进程。输入和输出进程由控制进程产生,和控制。三者的基本功能为: | |
输入进程。采集数据,将数据存储,并通知控制进程有需要处理的新数据。 | |
控制进程。控制输入与输出进程的生命周期。系统信息的接受,和发出控制指令,以及处理返回结果等。系统错误处理,例如终结无响应进程,对不可恢复错误进行报错等。 | |
输出进程。在接到控制程序指令后传输,和返回传输结果给主程序。 | |
这些进程间通信使用系统的IPC。当输入有输入是通知控制进程,控制进程转达给输出进程。完全分离输入和输出单位。输出的结果和错误处理由控制进程完成。 | |
这样做的原因是: | |
一)分离功能和分离可控和不可控的模块。尤其是输出进程的通讯部分牵涉与远程计算单元的网络通讯,应当和主控制系统分离。 | |
二)提高整体系统与环境交互的响应。控制进程完全使用非等待式的I/O处理。这个进程的运算以发送控制信令为主,要短暂,一个功能不可阻塞其它功能。 | |
三)安全考虑。控制进程可能需要一些特权权限。而其它进程则可以在提权限用户下执行。控制进程只接受本系统内的输入于输出,降低受外部使用输入攻击的风险。 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<title>test</title> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
/* | |
* @description 原始词库 | |
*/ |