我有一个大工厂,我正在试图弄清楚如何让它看起来很漂亮.
大约有40种可能的对象/构造函数组合:
if(algorithm == "SHA-1")
return new HashImpl<...>(algorithm, seed, size);
if(algorithm == "SHA-224")
return new HashImpl<...>(algorithm, seed, size);
if(algorithm == "SHA-256")
return new HashImpl<...>(algorithm, seed, size);
...
if(algorithm == "AES" || algorithm == "AES128")
return new BlockCipherImpl<...>(algorithm, seed, size);
...
if(algorithm == "HmacSHA1")
return new HmacImpl<...>(algorithm, seed, size);
...
Run Code Online (Sandbox Code Playgroud)
有没有办法将其放入地图中,这样我至少可以取消顺序搜索?我在弄清楚如何使构造函数成为一个仿函数时遇到了问题.
编辑:代码可以在这里找到:
http://code.google.com/p/owasp-esapi-cplusplus/source/browse/trunk/src/crypto/SecureRandomImpl.cpp,从第130行开始.
任何人都可以解释以下行为吗?该方法应该对加载的图像进行缩放,使其尽可能大,但不能超过某些范围.
private final File imageFile;
private final ImageLoaderListener listener;
private final int idealWidth;
private final int idealHeight;
private final float idealRatio;
@Override
protected BufferedImage doInBackground() throws Exception {
BufferedImage origImage;
BufferedImage scaledImage;
int origHeight;
int origWidth;
float imgRatio;
// Load the image.
try {
origImage = ImageIO.read( imageFile );
origHeight = origImage.getHeight();
origWidth = origImage.getWidth();
imgRatio = origWidth / origHeight;
//imgRatio = 5/7;
} catch (Exception e){
JOptionPane.showMessageDialog( AppFrame.getAppFrame(),
"Could not load the image.", "Error Loading Image",
JOptionPane.ERROR_MESSAGE );
return …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个包含 h1 和选择列表的基本标题栏 div。我希望选择列表位于 div 的最右侧,但将其向右浮动不起作用。有没有人有任何想法?代码很简单,但是看不出哪里出错了。谢谢!
<style type="text/css">
#select {
float: right;
}
h1 {
display: inline;
}
#titleBar {
width: 800px;
}
</style>
<body>
<div id="titleBar"><h1>Select Your Car </h1>
<select name="categories">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
这是 jsfiddle 的链接:http : //jsfiddle.net/qhvDG/1/
我有一个浮点数添加数字,它不显示我想要的所有小数点,例如我有1.25加上1.25作为浮点数,它显示为1.5.我怎么能让它显示为1.50?
假设您有一个项目列表,并将它们放在div中.该列表是动态生成的,项目数量未知.
CSS:
div#container {
width:500px;
}
div.item {
width:150px;
float:left;
}
HTML:
<div id="container">
<div class="item">item 1</div>
<div class="item">item 2</div>
<div class="item">item 3</div>
.
.
.
</div>
Run Code Online (Sandbox Code Playgroud)
浏览器输出如下:
项目1项目2项目3
项目4项目5项目6
......
如何创建垂直列,如:
项目1项目4
项目2项目5
项目3项目6
...
我在Python(2.6.1)词典中遇到了一个奇怪的行为:
我的代码是:
new_item = {'val': 1.4}
print new_item['val']
print new_item
Run Code Online (Sandbox Code Playgroud)
结果是:
1.4
{'val': 1.3999999999999999}
Run Code Online (Sandbox Code Playgroud)
为什么是这样?它发生在一些数字上,但不是其他数字.例如:
对,我有一个浮点数组,只存储1和0.我试图只是做一个简单的测试/检查数组中的当前插槽是1它将打印出一条消息说它是1,否则,它是0.继承我的代码:
if(myArray[i] == 1)
{
cout << "this is 1 !!!!!" << endl;
}
else
{
cout << "this is 0 ";
}
Run Code Online (Sandbox Code Playgroud)
但这只是继续进入"其他"部分.即只打印"这是0".它有什么问题(或者我的错误是什么?:P)??
如何float在python中打印超过10位数的数字?现在,什么时候做
print sqr_newton(10, 3, 0.001) (其中sqr_newton是newton的平方根算法;返回一个浮点数)
它只在小数位后给出这么多数字......我怎样才能得到更多?
我有一个以div元素为中心的问题.我想要居中的div元素应用了以下样式:
width: 60%;
float:right;
margin-left: auto;
margin-right: auto;
min-width: 300px;
Run Code Online (Sandbox Code Playgroud)
唯一的父标记是body标记,它应用了以下样式:
width:100%;
overflow-x:hidden;
Run Code Online (Sandbox Code Playgroud)
元素不是居中,而是与右边对齐.我之前将元素设置为"float:left",并且我没有将它居中的问题,但是当我将其更改为"float:right"时,元素不再居中.
这是我的代码片段:
float ab(float);
Run Code Online (Sandbox Code Playgroud)
然后
if(ab(temp)<ab(a[r][c]))
{ do something; }
Run Code Online (Sandbox Code Playgroud)
哪里
float temp;a[6][6];
Run Code Online (Sandbox Code Playgroud)
现在这个宣言究竟是什么float ab(float)以及以后如何使用它?