① C++中如何定义超长数组
你是不是把这个数组定义在了函数(比如main)里面?定义在函数里面的数组会存放在系统栈中,而系统栈的空间不很大,容易溢出。
你可以在定义时写:
static int a[100000000];
或者把数组定义放在函数外面作为全局变量。
② 用自己的语言说出php中数组的常用函数和用法
array_filter : 过滤数组中的无效元素,可以使用回调函数过滤
array_map : 使用回调函数依次处理所有元素
implode: 将一维数组转为特定符号隔开的字符串,
explode: 将特定符号隔开的字符串转为一维数组
sort /ksort: 将数组进行升序排序
array_unique: 将数组元素去重
array_values: 取数组的值,重新组成新数组
array_pop: 取数组末尾元素并删除(队列)
array_push:将一个元素插入数组末尾(队列)
array_sum:统计数组元素的和
array_column:将二维数组中的指定KEY取出组成一个一维数组
网页链接
③ 编写完整程序,使用函数对传送过来具有10个整数的数组进行如下操作:把数组中的所有奇数放在
#include<stdio.h>
#define NUM 10
int f(int *a,int *b,int n) { int i,k;
k=0; for ( i=0;i<n;i++ ) if ( a[i]%2!=0 ) { b[k]=a[i]; k++; }
return k;
}
void main() { int a[NUM]={0,51,32,43,84,25,16,7,18,39},b[N],n,i;
n=f(a,b,NUM); for ( i=0;i<n;i++ ) printf("%d ",b[i]); printf(" ");
}
文件或文件夹的加密、解密
'此方法对 WinXP 系统有效,Win98 没试验过。小心:不能用于系统文件或文件夹,否则会使系统瘫痪。
'加密:利用 API 函数在文件或文件夹名称末尾添上字符“..\”。比如,将文件夹“MyPath”更名为“MyPath..\”,在我的电脑中显示的名称就是“MyPath.”。系统会无法识别,此文件或文件夹就无法打开和修改,也无法删除。着名的病毒 Autorun 就是玩的这个小把戏。
'解密:去掉文件或文件夹名称末尾的字符“..\”
'将以下代码复制到 VB 的窗体代码窗口即可
'例子需控件:Command1、Command2、Text1,均采用默认属性设置
Private Const MAX_PATH = 260
Private Type FileTime ' 8 Bytes
LTime As Long
HTime As Long
End Type
Private Type Win32_Find_Data
dwFileAttributes As Long
ftCreationTime As FileTime
ftLastAccessTime As FileTime
ftLastWriteTime As FileTime
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cNameFile As String * MAX_PATH
cAlternate As String * 14
End Type
Private Declare Function MoveFileEx Lib "kernel32" Alias "MoveFileExA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal dwFlags As Long) As Long
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpNameFile As String, lpFindFileData As Win32_Find_Data) As Long
Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As Win32_Find_Data) As Long
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
Private Sub Form_Load()
Text1.Text = "C:\MyPath"
Command1.Caption = "解密": Command2.Caption = "加密"
Me.Caption = "目录或文件的加解密"
End Sub
Private Sub Command1_Click()
Call SetPathName(False) '解密
End Sub
Private Sub Command2_Click()
Call SetPathName(True) '加密
End Sub
Private Sub SetPathName(SetMi As Boolean)
Dim nName As String, NewName As String, nSort As String, nCap As String, dl As Long
nName = Trim(Text1.Text)
If Right(nName, 3) = "..\" Then nName = Left(nName, Len(nName) - 3)
If Right(nName, 1) = "\" Then nName = Left(nName, Len(nName) - 1)
If SetMi Then
NewName = nName & "..\"
Else
NewName = nName
nName = nName & "..\"
End If
If SetMi Then nCap = "加密" Else nCap = "解密"
nSort = GetShortName(nName) '转变其中的 ..\
If nSort = "" Then
MsgBox "文件没有找到:" & vbCrLf & nName, vbCritical, nCap
Exit Sub
End If
If MoveFileEx(nSort, NewName, 0) = 0 Then Exit Sub '文件更名:非零表示成功,支持只读文件
MsgBox nCap & "成功:" & vbCrLf & nName, vbInformation, nCap
End Sub
Public Function GetShortName(F As String, Optional ShortAll As Boolean) As String
'转变为短文件名,如果目录或文件不存在就返回空。可用于判断某目录或文件是否存在
'不能直接用 API 函数 GetShortPathName, 因它不支持 ..\
'ShortAll=T 表示全部转变为短名称,否则只转变其中的点点杠“..\”
Dim FondID As Long, ID1 As Long, S As Long, nPath As String
Dim nF As String, InfoF As Win32_Find_Data, qF As String, hF As String
Dim nName As String, nName1 As String
nF = F
Do
S = InStr(nF, "..\")
If S = 0 Then Exit Do
qF = Left(nF, S + 2): hF = Mid(nF, S + 3) '分为前后两部分
CutPathName qF, nPath, nName
nName = LCase(nName)
qF = nPath & "\" & "*."
FondID = FindFirstFile(qF, InfoF) '-1表示失败。查找所有文件(夹)
ID1 = FondID
Do
If FondID = Find_Err Or ID1 = 0 Then GoTo Exit1 '没有找到符合条件的条目
nName1 = LCase(CutChr0(InfoF.cNameFile)) '文件(夹)名称
If nName1 & ".\" = nName Then
nName1 = CutChr0(InfoF.cAlternate) '用短文件名代替
If hF = "" Then nF = nPath & "\" & nName1 Else nF = nPath & "\" & nName1 & "\" & hF
Exit Do
End If
ID1 = FindNextFile(FondID, InfoF) '查找下一个,0表示失败
Loop
FindClose FondID
Loop
Exit1:
FindClose FondID
S = MAX_PATH: nName = String(S, vbNullChar)
ID1 = GetShortPathName(nF, nName, S) '返回实际字节数,0表示失败
If ID1 = 0 Then Exit Function
If ShortAll Then
If ID1 > S Then
S = ID1: nName = String(S, vbNullChar)
ID1 = GetShortPathName(nF, nName, S) '返回实际字节数
End If
GetShortName = CutChr0(nName)
Else
GetShortName = nF
End If
End Function
Public Sub CutPathName(ByVal F As String, nPath As String, nName As String)
Dim I As Long, LenS As Long
LenS = Len(F)
For I = LenS - 1 To 2 Step -1
If Mid(F, I, 1) = "\" Then
nPath = Left(F, I - 1): nName = Mid(F, I + 1)
GoTo Exit1
End If
Next
nPath = F: nName = ""
Exit1:
If Right(nPath, 2) = ".." Then
nPath = nPath & "\"
Else
If Right(nPath, 1) = "\" Then nPath = Left(nPath, Len(nPath) - 1)
End If
If Right(nName, 1) = "\" And Right(nName, 3) <> "..\" Then nName = Left(nName, Len(nName) - 1)
End Sub
Private Function CutChr0(xx As String) As String
Dim S As Long
S = InStr(xx, vbNullChar)
If S > 0 Then CutChr0 = Left(xx, S - 1) Else CutChr0 = xx
End Function
'参考资料见下
⑤ 利用函数,对一个数组进行初始化赋0操作
举例说明:
int a[20] = {0};
这样,数组a中的每一个元素都被初始化为0了。
⑥ 用函数跟数组编程
Private Sub Form_Click()
Dim arr1(10) As Integer, k As Integer, s As Integer
For k = 0 To 10
arr1(k) = Int(Rnd * 900 + 100)
Next k
Call abc(arr1, s)
Print "数组元素之和为:" + CStr(s)
End Sub
Private Sub abc(arr2, ByRef ss)
For j = 0 To 10
ss = ss + arr2(j)
Next j
End Sub
我可以帮助你,你先设置我最佳答案后,我网络Hii教你。
⑦ 编写函数,使用选择排序法对数组进行排序(用C语言)
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
intmain(void)
{
inta[10],i,j,tmp,b;
srand(time(NULL));
for(i=0;i<10;i++)
a[i]=rand()%100;
for(i=0;i<10;i++)
printf("%3d",a[i]);
printf(" ");
for(i=0;i<9;i++)
{
tmp=i;
for(j=i+1;j<10;j++)
{
if(a[tmp]>a[j])
tmp=j;
}
if(i!=tmp)
{
b=a[tmp];
a[tmp]=a[i];
a[i]=b;
}
}
for(i=0;i<10;i++)
printf("%3d",a[i]);
printf(" ");
return0;
}
随机产生数组中的元素, 更合理一些。 网络中有各种版本。
⑧ JAVA字符串加密后(在线等)
private static void Md5(String plainText ) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(plainText.getBytes());
byte b[] = md.digest();
int i;
StringBuffer buf = new StringBuffer("");
for (int offset = 0; offset < b.length; offset++) {
i = b[offset];
if(i<0) i+= 256;
if(i<16)
buf.append("0");
buf.append(Integer.toHexString(i));
}
System.out.println("result: " + buf.toString());//32位的加密
System.out.println("result: " + buf.toString().substring(8,24));//16位的加密
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
MD5加密,位数是固定的
⑨ 如何用函数修改二维数组
使用二维数组作为参数时,(以整数为例)规范写法一般是:int
s[3][3]或int
s[][3]或int
(*s)[3]。
当然,如果你很熟练C语言,也可以使用int
**s的形式(
实际上可以使用任何形式
),这时只需要在函数内部做相应的处理即可,C语言相当灵活。初学者不建议使用。
下面在手机上用易历知食app里的微C程序设计编写个示例,演示使用规范的写法。程序中,函数Array1将二维数组的值设置为100-108之间;函数Array2将二维数组的值设置为200-208之间;函数PrintArray则打印出二维数组的值。从结果看,函数成功修改了二维数组的值了。
手机上C语言代码如下图:
手机上运行效果如下图:
⑩ C语言设计一个简单的加密解密程序
C语言设计一个简单的加密解密程序如下:
加密程序代码:
#include<stdio.h>
main()
{
char c,filename[20];
FILE *fp1,*fp2;
printf("请输入待加密的文件名:\n");
scanf("%s",filename);
fp1=fopen(filename,"r");
fp2=fopen("miwen.txt","w");
do
{
c=fgetc(fp1);
if(c>=32&&c<=126)
{
c=c-32;
c=126-c;
}
if(c!=-1)
fprintf(fp2,"%c",c);
}
while(c!=-1);
}
解密程序代码:
#include<stdio.h>
#include<string.h>
main()
{
char c,filename[20];
char yanzhengma[20];
FILE *fp1,*fp2;
printf("请输入待解密文件名:\n");
scanf("%s",filename);
printf("请输入验证码:\n");
scanf("%s",yanzhengma);
if(strcmp(yanzhengma,"shan")==0)
{
fp1=fopen(filename,"r");
fp2=fopen("yuanwen.txt","w");
do
{
c=fgetc(fp1);
if(c>=32&&c<=126)
{
c=126-c;
c=32+c;
}
if(c!=-1)
fprintf(fp2,"%c",c);
}
while(c!=-1);
}
else
{
printf("验证码错误!请重新输入:\n");
scanf("%s",filename);
}
}