我想为每个数字添加前导"0":
0000 & 1 = 00001
Run Code Online (Sandbox Code Playgroud)
但我需要计算长度,因为字符总数不应超过5,所以如果数字是30则那么excel应该显示为"00030".
如果它是100那么"00100".
然后,我将以下数字连接到结果:1027,因此,对于100,最终结果将是102700100.
我创建了一个类,但它的大小为零.现在,我怎样才能确定所有对象都有不同的地址?(我们知道,空类的大小不为零.)
#include<cstdio>
#include<iostream>
using namespace std;
class Test
{
int arr[0];//Why is the sizezero?
};
int main()
{
Test a,b;
cout <<"size of class"<<sizeof(a)<<endl;
if (&a == &b)// now how we ensure about address of objects ?
cout << "impossible " << endl;
else
cout << "Fine " << endl;//Why isn't the address the same?
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我希望能够在单个字符串(不是整个文件,只是程序中的一个字符串)中替换所有行返回(\n),空格和所有逗号在同一个字符串中用分号.
这是我的代码:
$str =~ s/"\n"/" "/g;
$str =~ s/","/";"/g;
Run Code Online (Sandbox Code Playgroud) Perl大师很容易...
我想要一个简单地接受项目数组(实际上是多个数组)的函数,并计算散列的关键部分中的每个项目的次数.但是,我真的不确定Perl哈希.
@array = qw/banana apple orange apple orange apple pear/
Run Code Online (Sandbox Code Playgroud)
我读到你需要使用这样的代码来做数组:
my %hash = (
'banana' => 0,
'orange' => 0,
'apple' => 0
#I intentionally left out pear... I only want the values in the array...
);
Run Code Online (Sandbox Code Playgroud)
但是,我正在努力获得一个循环工作,可以通过并添加一个值,相应的键等于数组中每个项目的值.
foreach $fruit (@array) {
if ($_ #is equal to a key in the hash) {
#Add one to the corresponding value
}
}
Run Code Online (Sandbox Code Playgroud)
这有几个基本功能全部包含在一起,所以代表所有刚开始的Perl程序员,提前谢谢!
我需要能够获取Perl字符串(YYYYMMDD格式的日期)并添加破折号(使其成为YYYY-MM-DD)格式.是否有捷径可寻?例如,对于1900年1月1日,我将输入19000101,如果需要1900-01-01则需要输入.