65,187
社区成员




file1.open("D:\\number.txt",ios::in);
if (!file1)
return -1;
int m = 100000;
int a = 0;
int i = 0;
while (i < m)
{
file1 >> a; //这样效率会不会太低???
//把a放进位图中
i++;
}
i = 0;
file2.open("D:\\result.txt", ios::out);
if (!file2)
return -1;
while (i < n) //遍历位图
{
if (test(i))
{
file2 << i << endl; //这样效率会不会太低???
}
i++;
}
#include <stdio.h>
#include <stdlib.h>
FILE *f;
int i;
int v;
int n;
int m[100000];
int compare(const void *a,const void *b) {
return (*((int *)a)) - (*((int *)b));
}
int main() {
f=fopen("D:\\number.txt","r");
if (NULL==f) {
printf("Can not find file D:\\number.txt!\n");
return 1;
}
i=0;
while (1) {
if (feof(f)) break;
if (1==fscanf(f,"%d",&v)) {
m[i]=v;
i++;
if (i>=100000) break;
} else {
fscanf(f,"%*c");
}
}
fclose(f);
n=i;
qsort(m, n, sizeof(int), compare);
f=fopen("D:\\result.txt","w");
if (NULL==f) {
printf("Can not create file D:\\result.txt!\n");
return 1;
}
for (i=0;i<n;i++) fprintf(f,"%d\n",m[i]);
fclose(f);
return 0;
}