我可以使用什么代替可以克隆的"长"?
请参阅下面我在此处收到错误的代码,因为长期不可克隆.
public static CloneableDictionary<string, long> returnValues = new CloneableDictionary<string, long>();
Run Code Online (Sandbox Code Playgroud)
编辑:我忘了提到我想使用我找到的以下代码(见下文).
public class CloneableDictionary<TKey, TValue> : Dictionary<TKey, TValue> where TValue : ICloneable
{
public IDictionary<TKey, TValue> Clone()
{
var clone = new CloneableDictionary<TKey, TValue>();
foreach (KeyValuePair<TKey, TValue> pair in this)
{
clone.Add(pair.Key, (TValue)pair.Value.Clone());
}
return clone;
}
}
Run Code Online (Sandbox Code Playgroud) 我从C++中的数据文件中获得了一些信息.一个信息是12个字符长的数字.如何在没有数据丢失的情况下将其从字符串转换为long long(我认为long long最适合这个)?
我将向您展示一个非常简单的示例,非常用递归调用阶乘计数,但有一个非常重要的细节,让我们看看我的代码,然后我会写出我的问题.
#define PASSWORD_MAX 0x28
typedef unsigned long long longtype;
#include <iostream>
using namespace std;
longtype f(longtype n)
{
return (n <= 1) ? 1 : f(n - 1) * n;
};
void main(void)
{
for(longtype i = 0; i <= PASSWORD_MAX; i++)
{
if(f(i) != 0) cout << i << " -> " << f(i) << endl;
};
};
Run Code Online (Sandbox Code Playgroud)
在这段代码之后,我得到了下一个结果:http://pastebin.com/ZHPtJBZ7
最大结果是可读的:22 - > 17196083355034583040
从23到最后,根据我的理解,只有"e"电源中的数字,如何从23完全打印值,而不是缩短格式?
谢谢,最诚挚的问候!
我想将长(TBs中的巨大文件大小)除以某个数字(巨大的int)并安全地得到一个int.但是对于类型转换属性,int变长并且结果很长.我确定我的商是一个int,正在投入,或者请指导我找一个更好的解决方案.
这篇Stackoverflow 文章讨论了数字溢出的潜在问题,如果不附加L到数字:
这是REPL的一个例子:
scala> 100000 * 100000 // no type specified, so numbers are `int`'s
res0: Int = 1410065408
Run Code Online (Sandbox Code Playgroud)
避免这个问题的一种方法是使用L.
scala> 100000L * 100000L
res1: Long = 10000000000
Run Code Online (Sandbox Code Playgroud)
或者指定数字的类型:
scala> val x: Long = 100000
x: Long = 100000
scala> x * x
res2: Long = 10000000000
Run Code Online (Sandbox Code Playgroud)
什么被认为是正确指定数字类型的最佳做法?
通常,我使用String.sustring(int, int)方法来获取文本的某些部分.如果文字太大,那么我无法使用Integer类型变量访问某个位置,有什么方法可以解决这个问题?
例如:
我想用 String.substring(Long, Long)
我正在编译一个使用for循环的Java程序来找出long的最大值.但是,运行程序时没有打印任何内容.为什么?
这是我的代码:
class LongMaxMin {
public static void main(String args[]) {
long i = 0L;
long result = 0L;
for (; ; ) {
result = i++;
if (i<0)
break;
}
System.out.println("The biggest integer:" + result);
}
Run Code Online (Sandbox Code Playgroud) 当传递1113355579999作为参数时,该值在函数内部更改为959050335.
调用(main.c中):
printf("%d\n", FindCommonDigit(1113355579999, 123457));
Run Code Online (Sandbox Code Playgroud)
功能(ex4.c):
int FindCommonDigit(long int n1, long int n2) { printf("%d\n", n1); }
Run Code Online (Sandbox Code Playgroud)
有什么问题?值得一提的是,在到达之前价值会发生变化printf.
我想检查数据类型int,long及其无符号形式的大小,最大值和最小值.我的程序的输出显示int和long都具有相同的大小,最大值和最小值,同样是无符号形式.这是我的程序的输出:
Size of int : 4 byte, Max value : 2147483647, Min value : -2147483648
Size of long : 4 byte, Max value : 2147483647, Min value : -2147483648
Size of unsigned int : 4 byte, Max value : 4294967295, Min value : 0
Size of unsigned long : 4 byte, Max value : 4294967295, Min value : 0
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
#include <stdio.h>
#include <limits.h>
int main(int argc, char *argv[])
{
printf("Size of int : %ld byte, Max value : %d, …Run Code Online (Sandbox Code Playgroud) 我有几行代码将Long值转换为Int。据我所知,如果Long值大于然后,Int.MAX_VALUE即2147483647它将截断Long值以给出结果Int。我尝试了不同的示例:
val num1: Long = 5453448989999998988
val num2: Int = num1.toInt()
Run Code Online (Sandbox Code Playgroud)
给
num2 = 2041161740
val num1: Long = 5453448989999998
val num2: Int = num1.toInt()
Run Code Online (Sandbox Code Playgroud)
给
num2 = 165249918
两个输入都超出范围。但是我的问题是,为什么我期望截断的输出会得到不同的输出。