20130317 如何批量把文件名称写入txt文档
1、如何批量把文件名称写入txt文档
COMMAND 窗口
例:存放图片的文件夹是 D:\123\
就用下面一名命令就OK
dir d:\123\*.jpg /b > A.TXT
那么你所以JPG格式的图片和文件名全部输出到了D:\123\ A.TXT中。
就这么简单哦
2、寻找和为定值的两个数(前提是数组已经排好序),以引用做为函数参数
#include<stdio.h> bool find_num(int data[],unsigned int length, int sum,int &first_num,int &second_num) { if(length<1) return true; int begin=0; int end=length-1; while(end>begin) { long current_sum=data[begin]+data[end]; if(current_sum==sum) { first_num=data[begin]; second_num=data[end]; return true; } else if(current_sum>sum) end--; else begin++; } return false; } void main() { int a[]={1,2,4,7,11,15}; int sum=15; int length=sizeof(a)/4; int first_num=0,second_num=0; find_num(a,length,sum,first_num,second_num); printf("%d,%d",first_num,second_num); }
3、二分查找,返回下标,注意0<=left<=right左闭右闭区间和0<=left<right左闭右开区间
//循环终止条件为0<=left<=right左闭右闭区间
#include<stdio.h> int search(int array[],int n,int v) { int left,right,middle; left=0,right=n-1; while(left<=right) //循环终止条件为:left<=right,对应的left,right区间修改规则为:right=middle-1和left=middle+1 { middle=left+(right-left)/2;//不对应的话可能出现找不到的情况 if(array[middle]>v) { right=middle-1; } else if(array[middle]<v) { left=middle+1; } else { return middle; } } return -1; } void main() { int a[]={1,4,7,11,15}; int value_search=15; int length=sizeof(a)/4; int index=search(a,length,value_search); printf("%d",index); }
//fsdf0<=left<right左闭右开区间
#include<stdio.h> int search(int array[], int n, int v) { int left, right, middle; left = 0, right = n; while (left < right) { middle = left + (right-left)/2; if (array[middle] > v) { right = middle; } else if (array[middle] < v) { left = middle + 1; } else { return middle; } } return -1; } void main() { int a[]={1,4,7,11,15}; int value_search=4; int length=sizeof(a)/4; int index=search(a,length,value_search); printf("%d",index); }
4、哈希表查找和为定值的两个数(数组有序无序都可以)
#include<stdio.h> void main() { int a[]={1,4,7,8,11,15}; int sum=15; int length=6; int hash_tab[15]={0}; for(int i=0;i<length;i++) { hash_tab[sum-a[i]]++; } for(int j=0;j<length;j++) { if(hash_tab[a[j]]!=0) {printf("%d , %d\n",a[j],sum-a[j]);break;} } }