这是我的第一个Haskell程序.你会用更好的方式写什么部分?
-- Multiplication table
-- Returns n*n multiplication table in base b
import Text.Printf
import Data.List
import Data.Char
-- Returns n*n multiplication table in base b
mulTable :: Int -> Int -> String
mulTable n b = foldl (++) (verticalHeader n b w) (map (line n b w) [0..n])
where
lo = 2* (logBase (fromIntegral b) (fromIntegral n))
w = 1+fromInteger (floor lo)
verticalHeader :: Int -> Int -> Int -> String
verticalHeader n b w = (foldl (++) tableHeader …Run Code Online (Sandbox Code Playgroud) 我正在寻找一个脚本来生成您看到的目录结构的图形化文本表示.我能像这样运行的东西:
james@computer:/.../basedir$ listdir .
basedir
|-firstsubdir
| |-file
| `-subsubdir
| |-file1
| |-file2
| |-file3
| `-file4
`-secondsubdir
james@computer:/.../basedir$
Run Code Online (Sandbox Code Playgroud)
据推测,存在一个既定的脚本?我必须写吗?
我在这里搜索了很多关于自定义用户身份验证的帖子,但没有一个解决了我的所有问题
我是ASP.NET MVC的新手并使用传统的ASP.NET(WebForms),但不知道如何为使用ASP.NET MVC的用户构建登录/身份验证机制.
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
string userName = Login1.UserName;
string password = Login1.Password;
bool rememberUserName = Login1.RememberMeSet;
if (validateuser(userName, password))
{
//Fetch the role
Database db = DatabaseFactory.CreateDatabase();
//Create Command object
System.Data.Common.DbCommand cmd = db.GetStoredProcCommand("sp_RolesForUser");
db.AddInParameter(cmd, "@Uid", System.Data.DbType.String, 15);
db.SetParameterValue(cmd, "@Uid", Login1.UserName);
System.Data.IDataReader reader = db.ExecuteReader(cmd);
System.Collections.ArrayList roleList = new System.Collections.ArrayList();
if (reader.Read())
{
roleList.Add(reader[0]);
string myRoles = (string)roleList[0];
//Create Form Authentication ticket
//Parameter(1) = Ticket version
//Parameter(2) = User ID
//Parameter(3) = Ticket …Run Code Online (Sandbox Code Playgroud) 我有一个Unicode字符串,不知道它的编码是什么.当Perl程序读取此字符串时,是否存在Perl将使用的默认编码?如果是这样,我怎么知道它是什么?
我试图从输入中删除非ASCII字符.我在一些论坛上发现了这个:
my $line = encode('ascii', normalize('KD', $myutf), sub {$_[0] = ''});
Run Code Online (Sandbox Code Playgroud)
如果没有指定输入编码,上面的工作如何?是否应该如下指定?
my $line = encode('ascii', normalize('KD', decode($myutf, 'input-encoding'), sub {$_[0] = ''});
Run Code Online (Sandbox Code Playgroud) 每个Delphi 7开发人员都知道,如果他在Delphi 7上编译应用程序,那么样式将是Windows 2000应用程序,但是有任何方法可以使这个更好,因为应用程序可以拥有Windows版本的默认主题,如C++和C#应用程序?
import numpy as np
a = np.arange(1000000).reshape(1000,1000)
print(a**2)
Run Code Online (Sandbox Code Playgroud)
有了这段代码,我得到了这个答案.为什么我会得到负值?
[[ 0 1 4 ..., 994009 996004 998001]
[ 1000000 1002001 1004004 ..., 3988009 3992004 3996001]
[ 4000000 4004001 4008004 ..., 8982009 8988004 8994001]
...,
[1871554624 1873548625 1875542628 ..., -434400663 -432404668 -430408671]
[-428412672 -426416671 -424420668 ..., 1562593337 1564591332 1566589329]
[1568587328 1570585329 1572583332 ..., -733379959 -731379964 -729379967]]
Run Code Online (Sandbox Code Playgroud) 我有一个lambda表达式,可以从Dictionary获得结果.
var sortedDict = (from entry in dctMetrics
orderby entry.Value descending
select entry);
Run Code Online (Sandbox Code Playgroud)
表达式拉回了我需要的对,我可以在IDE的调试模式中看到它们.
如何将此转换回与源相同类型的字典?我知道sortedDict的TElement是一个KeyValuePair,但是我无法完全理解ToDictionary扩展方法的语法.我也尝试将var结果分段构造一个新的字典,但无济于事.
有这样的东西(功能明智):
var results = (from entry in dictionary
orderby entry.Value descending
select entry);
Dictionary<string,float> newDictionary = results as (Dictionary<string,float>);
Run Code Online (Sandbox Code Playgroud) 找到最小化 c 的向量 x 。x 受约束 m 。x >= b,x 整数。
这是一个示例输入集:
c : {1,2,3}
m : {{1,0,0},
{0,1,0},
{1,0,1}}
b : {1,1,1}
Run Code Online (Sandbox Code Playgroud)
有输出:
x = {1,1,0}
Run Code Online (Sandbox Code Playgroud)
什么是解决此类问题的好工具,以及如何使用它们的示例?
我有以下C代码:
int *a;
size_t size = 2000*sizeof(int);
a = (int *) malloc(size);
Run Code Online (Sandbox Code Playgroud)
哪个工作正常.但如果我有以下内容:
char **b = malloc(2000*sizeof *b);
Run Code Online (Sandbox Code Playgroud)
每个元素b都有不同的长度.
怎么可能b像我一样做同样的事情a; 即以下代码是否正确?
char *c;
size_t size = 2000*sizeof(char *);
c = (char *) malloc(size);
Run Code Online (Sandbox Code Playgroud) 我在编译时得到一个我没想到的匿名类.相关代码如下,然后更详细的解释:
CircuitType.java的整体:
public enum CircuitType { V110A20, V110A30, V208A20, V208A30 }
Run Code Online (Sandbox Code Playgroud)
来自Auditor.java,第3-9行:
public class Auditor {
private String[] fileNames;
private int numV110A20;
private int numV110A30;
private int numV208A20;
private int numV208A30;
Run Code Online (Sandbox Code Playgroud)
来自Auditor.java,第104-121行:
[...]
switch (newCircuit.getType()) {
case V110A20:
this.numV110A20++;
break;
case V110A30:
this.numV110A30++;
break;
case V208A20:
this.numV208A20++;
break;
case V208A30:
this.numV208A30++;
break;
default:
System.err.println("An Error Has Occured.");
System.exit(-1);
break;
}
[...]
Run Code Online (Sandbox Code Playgroud)
从Circuit.java,第1-5行:
public class Circuit {
private CircuitType myType;
public CircuitType getType() {
return this.myType;
}
[...]
Run Code Online (Sandbox Code Playgroud)
当命令
javac *.java …Run Code Online (Sandbox Code Playgroud)