Categories
不学无术

1029. Median (25)

Given an increasing sequence S of N integers, the median is the number at the middle position. For example, the median of S1={11, 12, 13, 14} is 12, and the median of S2={9, 10, 15, 16, 17} is 15. The median of two sequences is defined to be the median of the nondecreasing sequence which contains all the elements of both sequences. For example, the median of S1 and S2 is 13.
Given two increasing sequences of integers, you are asked to find their median.
Input
Each input file contains one test case. Each case occupies 2 lines, each gives the information of a sequence. For each sequence, the first positive integer N (<=1000000) is the size of that sequence. Then N integers follow, separated by a space. It is guaranteed that all the integers are in the range of long int.
Output
For each test case you should output the median of the two given sequences in a line.
Sample Input

4 11 12 13 14
5 9 10 15 16 17

Sample Output

13

====================================
这题其实没什么技术含量,因为输入序列都帮你排序好了,时间内存都没啥限制
要注意的一点就是,假定输入序列为A,B,当A或B某个已经被掏空时,需要另外处理,不然就会报段错误什么的…
在优化方面,其实可以先读第一个序列进队列,第二个序列读入时直接处理而不存储,能比原来节省一半空间。
由于题目比较松,没有做这方面处理。
====================================

#include 
#include 
using namespace std;
int main()
{
	///////////Init
	queue q_a ,q_b;
	long N1, N2; //两个序列的长度
	//不存储第二个序列,直接用来比较处理
	///////////
	//读第一个序列
	scanf("%ld", &N1);
	long temp;
	for(long i=0; i

另外测试结果比较恐怖,哈哈
测试点 结果 用时(ms) 内存(kB) 得分/满分
0 答案正确 0 660 4/4
1 答案正确 0 790 2/2
10 答案正确 320 17270 3/3
11 答案正确 320 17260 1/1
12 答案正确 320 17260 3/3
13 答案正确 0 740 1/1
2 答案正确 0 740 4/4
3 答案正确 0 750 1/1
4 答案正确 0 790 1/1
5 答案正确 0 750 1/1
6 答案正确 150 9000 1/1
7 答案正确 160 9000 1/1
8 答案正确 160 9010 1/1
9 答案正确 150 8870 1/1

Categories
不学无术

C++ 精确到纳秒计时

#include 
using namespace std;
inline unsigned __int64 GetCycleCount()
{
	__asm _emit 0x0f
	__asm _emit 0x31
}
int main()
{
	unsigned long t0, t1;
	t0 = GetCycleCount();
	t1 = GetCycleCount();
	cout << t1 - t0 << endl;
	return 0;
}

参考文献:http://yanlinjust79.blog.163.com/blog/static/16950848220107254332975/

在Intel Pentium以上级别的CPU中,有一个称为“时间戳(Time Stamp)”的部件,它以64位无符号整型数的格式,记录了自CPU上电以来所经过的时钟周期数。由于目前的CPU主频都非常高,因此这个部件可以达到纳秒级的计时精度。这个精确性是上述两种方法所无法比拟的。
在Pentium以上的CPU中,提供了一条机器指令RDTSC(Read Time Stamp Counter)来读取这个时间戳的数字,并将其保存在EDX:EAX寄存器对中。由于EDX:EAX寄存器对恰好是Win32平台下C++语言保存函数返回值的寄存器,所以我们可以把这条指令看成是一个普通的函数调用。
这个方法的优点是:
1.高精度。可以直接达到纳秒级的计时精度(在1GHz的CPU上每个时钟周期就是一纳秒),这是其他计时方法所难以企及的。
2.成本低。timeGetTime 函数需要链接多媒体库winmm.lib,QueryPerformance* 函数根据MSDN的说明,需要硬件的支持(虽然我还没有见过不支持的机器)和KERNEL库的支持,所以二者都只能在Windows平台下使用(关于DOS平台下的高精度计时问题,可以参考《图形程序开发人员指南》,里面有关于控制定时器8253的详细说明)。但RDTSC指令是一条CPU指令,凡是i386平台下Pentium以上的机器均支持,甚至没有平台的限制(我相信i386版本UNIX和Linux下这个方法同样适用,但没有条件试验),而且函数调用的开销是最小的。
3.具有和CPU主频直接对应的速率关系。一个计数相当于1/(CPU主频Hz数)秒,这样只要知道了CPU的主频,可以直接计算出时间。这和QueryPerformanceCount不同,后者需要通过QueryPerformanceFrequency获取当前计数器每秒的计数次数才能换算成时间。
这个方法的缺点是:
1.现有的C/C++编译器多数不直接支持使用RDTSC指令,需要用直接嵌入机器码的方式编程,比较麻烦。
2.数据抖动比较厉害。其实对任何计量手段而言,精度和稳定性永远是一对矛盾。如果用低精度的timeGetTime来计时,基本上每次计时的结果都是相同的;而RDTSC指令每次结果都不一样,经常有几百甚至上千的差距。这是这种方法高精度本身固有的矛盾。

Categories
不学无术

1008. Elevator (20)

The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seconds to move down one floor. The elevator will stay for 5 seconds at each stop.
For a given request list, you are to compute the total time spent to fulfill the requests on the list. The elevator is on the 0th floor at the beginning and does not have to return to the ground floor when the requests are fulfilled.
Input Specification:
Each input file contains one test case. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100.
Output Specification:
For each test case, print the total time on a single line.
Sample Input:

3 2 3 1

Sample Output:

41

==============================================
此题初看还以为是电梯算法,其实啥都不是。。。。
注意的是第一个输入的数字是后面的总的输入个数,不是别的其他什么…
答案也很短…好久没碰到这么简单的了
==============================================

#include 
using namespace std;
int main(int argc, char* argv[])
{
	int N;
	cin >> N;
	int floor_now = 0; //当前在0层
	int next_floor = 0;
	int total_time = 0;
	for(int i=0; i> next_floor;
		int time_per_floor = (next_floor - floor_now > 0) ? 6 : -4; //上楼还是下楼
		total_time = total_time + time_per_floor * (next_floor - floor_now) + 5;
		floor_now = next_floor;
	}
	cout << total_time;
	return 0;
}
Categories
不学无术

1035. Password (20)

To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem is that there are always some confusing passwords since it is hard to distinguish 1 (one) from l (L in lowercase), or 0 (zero) from O (o in uppercase). One solution is to replace 1 (one) by @, 0 (zero) by %, l by L, and O by o. Now it is your job to write a program to check the accounts generated by the judge, and to help the juge modify the confusing passwords.
Input Specification:
Each input file contains one test case. Each case contains a positive integer N (<= 1000), followed by N lines of accounts. Each account consists of a user name and a password, both are strings of no more than 10 characters with no space.
 
Output Specification:
For each test case, first print the number M of accounts that have been modified, then print in the following M lines the modified accounts info, that is, the user names and the corresponding modified passwords. The accounts must be printed in the same order as they are read in. If no account is modified, print in one line “There are N accounts and no account is modified” where N is the total number of accounts. However, if N is one, you must print “There is 1 account and no account is modified” instead.
Sample Input 1:

3
Team000002 Rlsp0dfa
Team000003 perfectpwd
Team000001 R1spOdfa

Sample Output 1:

2
Team000002 RLsp%dfa
Team000001 R@spodfa

Sample Input 2:

1
team110 abcdefg332

Sample Output 2:

There is 1 account and no account is modified

Sample Input 3:

2
team110 abcdefg222
team220 abcdefg333

Sample Output 3:

There are 2 accounts and no account is modified

======================================
这题没啥技术含量,直接发代码

#include 
#include 
using namespace std;
int main()
{
	int N;
	scanf("%d", &N);
	bool isModified = false;
	int modCount = 0;
	char name[11], pswd[11];
	char *ptrPswd;
	string strOut;
	for(int i=0; i

		
Categories
不学无术

C++ Gossip: 隨機存取檔案

本文来自:http://openhome.cc/Gossip/CppGossip/RadomAccessFile.html

使用 get 指標或 put 指標,可以自由的移動至檔案中指定的位置進行讀取或寫入的動作,通常隨機存取檔案會使用二進位模式進行,文字模式開啟的檔案並不適合作隨機存取的動作。
如何利用隨機存取來讀寫所有的資料,必須視您的需求而定,需求決定您的資料結構,這邊以一個最簡單的例子來示範隨機存取,寫入檔案時都是使用固定大小的struct,由於資料大小固定,這可以方便明確的指定檔案中讀取的位置。
假設有一個簡單的學生成績資料如下:

  • Student.h
#ifndef DATASTRU_H
#define DATASTRU_H
struct Student {
    int studyNumber;
    char name[80];
    double score;
};
#endif

一個結構的大小是固定的,當要寫入一個結構時,可以使用這樣的語法:

fout.write(reinterpret_cast<const char*> (&student),
            sizeof(Student));


其中student是Student自訂struct所宣告的變數名稱,由於write接受const char*型態的變數,所以使用reinterpret_cast<const char*> 將之轉換為const char*指標。
下面這個程式示範,如何建立一個檔案,當中包括50筆空的資料:

  • main.cpp
#include <iostream>
#include <fstream>
#include "Student.h"
using namespace std;
int main(int argc, char* argv[]) {
    if(argc != 2) {
        cout << "指令: create <filename>" << endl;
        return 1;
    }
    ofstream fout(argv[1], ios::binary);
    if(!fout) {
        cerr << "檔案輸出失敗" << endl;
        return 1;
    }
    int count;
    cout << "要建立幾筆資料? ";
    cin >> count;
    Student student = {0, "", 0.0};
    for(int i = 0; i < count; i++) {
        fout.write(reinterpret_cast<const char*> (&student),
            sizeof(Student));
    }
    fout.close();
    return 0;
}

執行結果:

create data.bin
要建立幾筆資料? 50

接下來可以使用下面這個程式進行隨機存取,使用學號來作資料的位置指定,將之儲存在檔案中的指定位置:

#include <iostream>
#include <fstream>
#include "Student.h"
using namespace std;
int main(int argc, char* argv[]) {
    Student student;
    int count = 0;
    if(argc < 2) {
        cerr << "指令: write <filename>";
        return 1;
    }
    fstream fio(argv[1], ios::in | ios::out | ios::binary);
    if(!fio) {
        cerr << "無法讀取檔案" << endl;
        return 1;
    }
    while(true) {
        fio.read(reinterpret_cast<char *> (&student),
            sizeof(Student));
        if(!fio.eof())
            count++;
        else
            break;
    }
    fio.clear();
    cout << "輸入學號(1-" << count << ")"  << endl
         << "輸入0離開";
    while(true) {
        cout << "n學號? ";
        cin >> student.studyNumber;
        if(student.studyNumber == 0)
            break;
        cout << "輸入姓名, 分數" << endl
             << "? ";
        cin >> student.name >> student.score;
        fio.seekp((student.studyNumber - 1) * sizeof(Student));
        fio.write(reinterpret_cast<const char*> (&student),
            sizeof(Student));
    }
    fio.close();
    return 0;
}

執行結果:

write data.bin
輸入學號(1-50)
輸入0離開
學號? 1
輸入姓名, 分數
? 良葛格 88
學號? 2
輸入姓名, 分數
? 毛妹妹 94
學號? 5
輸入姓名, 分數
? 毛毛蟲 75
學號? 0

接下來可以使用下面這個程式讀取方才所輸入的資料:

#include <iostream>
#include <fstream>
#include "Student.h"
using namespace std;
int main(int argc, char* argv[]) {
    Student student;
    int count = 0, number;
    if(argc != 2) {
        cout << "指令: read <filename>" << endl;
        return 1;
    }
    ifstream fin(argv[1], ios::in | ios::binary);
    if(!fin) {
        cerr << "無法讀取檔案" << endl;
        return 1;
    }
    while(true) {
        fin.read(reinterpret_cast<char *> (&student),
            sizeof(Student));
        if(!fin.eof())
            count++;
        else
            break;
    }
    fin.clear();
    cout << "輸入學號(1-" << count << ")"  << endl
         << "輸入0離開";
    while(true) {
        cout << "n學號? ";
        cin >> number;
        if(number == 0)
            break;
        else if(number > count) {
            cout << "輸入學號(1-" << count << ")" << endl;
            continue;
        }
        cout << "n學號t姓名tt分數" << endl;
        fin.seekg((number - 1) * sizeof(Student));
        fin.read(reinterpret_cast<char*> (&student),
            sizeof(Student));
        cout << student.studyNumber << "t"
             << student.name << "tt"
             << student.score << endl;
    }
    fin.close();
    return 0;
}

執行結果:

read data.bin
輸入學號(1-50)
輸入0離開
學號? 1
學號    姓名            分數
1       良葛格          88
學號? 2
學號    姓名            分數
2       毛妹妹          94
學號? 3
學號    姓名            分數
0                       0
學號? 5
學號    姓名            分數
5       毛毛蟲          75
學號? 0

這幾個程式是隨機存取的簡單示範,您也可以結合起來,製作一個簡易的成績登記程式。
在判斷資料筆數時還有更簡單的方法,就是開啟檔案後先使用ios::end將指標移至檔案尾,然後使用tellg()得到目前的檔案指標位置,再除以資料結構的大小除可得知資料筆數,例如:

file.seekg(0, ios::end);
count = file.tellg() / sizeof(資料結構);
 


 

关闭提示 关闭

确 认 取 消

Categories
不学无术

WINDOWS API 文件操作

1. 打开和关闭文件:

  HANDLE CreateFile(

  LPCTSTR lpFileName,                         // file name

  DWORD dwDesiredAccess,                      // access mode

  DWORD dwShareMode,                          // share mode

  LPSECURITY_ATTRIBUTES lpSecurityAttributes, // SD

  DWORD dwCreationDisposition,                // how to create

  DWORD dwFlagsAndAttributes,                 // file attributes

  HANDLE hTemplateFile                       // handle to template file

);

CreateFile函数相当强大,Windows下的底层设备差不多都是由它打开的。它可以创建或打开文件、目录、物理磁盘、控制台缓冲区、邮槽和管道等。具体参考MSDN。

2. 移动文件指针:

  DWORD SetFilePointer(
  HANDLE hFile,                // handle to file
  LONG lDistanceToMove,        // bytes to move pointer
  PLONG lpDistanceToMoveHigh,  // bytes to move pointer
  DWORD dwMoveMethod           // starting point
);
 
设置文件结尾标志:
BOOL SetEndOfFile(
  HANDLE hFile   // handle to file
);
该函数移动指定文件的结束标志到文件指针指向的位置。可用来截断或者扩展文件,如果文件扩展,旧的EOF位置和新的EOF位置间的内容是未定义的。参考MSDN。

3. 文件读写:
  BOOL ReadFile(
  HANDLE hFile,                // handle to file
  LPVOID lpBuffer,             // data buffer
  DWORD nNumberOfBytesToRead// number of bytes to read
  LPDWORD lpNumberOfBytesRead, // number of bytes read
  LPOVERLAPPED lpOverlapped    // overlapped buffer
);
 
 文件读取函数
 
  BOOL WriteFile(
  HANDLE hFile,                    // handle to file
  LPCVOID lpBuffer,                // data buffer
  DWORD nNumberOfBytesToWrite,     // number of bytes to write
  LPDWORD lpNumberOfBytesWritten// number of bytes written
  LPOVERLAPPED lpOverlapped        // overlapped buffer
);

 文件写入函数,当Windows文件写文件时,写的的文件通常被Windows暂时保存在内部的高速缓存中,等合适的时间再一并写入磁盘,可以调用FlushFileBuffer(HANDLE hFile  // handle to file)函数来清空数据缓冲区

这两个函数可以同步读写文件,又可以异步读写文件。另外两个函数ReadFileEx和WriteFileEx只能异步读写文件。比上面函数多了一个参数 :

LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine // completion routine

4. 文件锁定与解锁:

  BOOL LockFile(
  HANDLE hFile,                   // handle to file
  DWORD dwFileOffsetLow,          // low-order word of offset
  DWORD dwFileOffsetHigh,         // high-order word of offset
  DWORD nNumberOfBytesToLockLow// low-order word of length
  DWORD nNumberOfBytesToLockHigh  // high-order word of length
);
  BOOL UnlockFile(
  HANDLE hFile,                    // handle to file
  DWORD dwFileOffsetLow,           // low-order word of start
  DWORD dwFileOffsetHigh,          // high-order word of start
  DWORD nNumberOfBytesToUnlockLow, // low-order word of length
  DWORD nNumberOfBytesToUnlockHigh // high-order word of length
);

这两个函数用于当对文件数据一致性要求较高时,为防止程序在写入的过程中其他进程刚好在读取写入的内容,可以对已打开文件的某个部分进行加锁。

函数参数中dwFileOffsetLow和dwFileOffsetHigh参数组合起来指定了加锁区域的开始位置,nNumberOfBytesTLockLow和nNumberOfBytesToLockHigh参数组合起来指定了加锁区域的大小。如果对文件进行了加锁后,当确定程序不在使用时,最好调用UnlockFile显式的解锁,虽然操作系统会对其自动解锁,但操作系统解锁的用的时间取决于当前可用的系统资源,所以有可能造成文件的无法访问。

5. 获取文件信息

  DWORD GetFileType(
  HANDLE hFile   // handle to file
);

获取文件类型,其返回值可参考MSDN。

  DWORD GetFileSize(
  HANDLE hFile,           // handle to file
  LPDWORD lpFileSizeHigh  // high-order word of file size
);

获取文件的大小,函数执行成功将返回文件大小的低双字,如果lpFileSizeHigh参数不是NULL,函数将文件大小的高双字放入它指向的DWORD变量中

  DWORD GetFileAttributes(
  LPCTSTR lpFileName   // name of file or directory
);

如果要查看文件或者目录的属性,可以使用GetFileAttributes函数,它会返回一系列的FAT风格属性信息。返回值可参考MSDN。

  BOOL SetFileAttributes(
  LPCTSTR lpFileName,      // file name
  DWORD dwFileAttributes   // attributes
);

设置文件属性

  BOOL GetFileTime(
  HANDLE hFile,                 // handle to file
  LPFILETIME lpCreationTime,    // creation time
  LPFILETIME lpLastAccessTime// last access time
  LPFILETIME lpLastWriteTime    // last write time
);

获取文件时间,有三个文件时间可供获取:创建时间、最后访问时间、最后写时间。参数具体信息可参考MSDN

  BOOL GetFileInformationByHandle(
  HANDLE hFile,                                  // handle to file
  LPBY_HANDLE_FILE_INFORMATION lpFileInformation // buffer
);

获取所有文件信息,该函数能够获取文件的所有信息,如大小,属性等,另外还有一些其它信息,如文件卷标,索引和链接信息。返回信息保存在lpFileInformation所指向的BY_HANDLE_FILE_INFORMATION中

typedef struct _BY_HANDLE_FILE_INFORMATION {
  DWORD    dwFileAttributes;
  FILETIME  ftCreationTime;
  FILETIME  ftLastAccessTime;
  FILETIME  ftLastWriteTime;
  DWORD    dwVolumeSerialNumber;
  DWORD    nFileSizeHigh;
  DWORD    nFileSizeLow;
  DWORD    nNumberOfLinks;
  DWORD    nFileIndexHigh;
  DWORD    nFileIndexLow;
} BY_HANDLE_FILE_INFORMATION, *PBY_HANDLE_FILE_INFORMATION;
关于此结构的具体信息参考MSDN。
  DWORD GetFullPathName(
  LPCTSTR lpFileName// file name
  DWORD nBufferLength, // size of path buffer
  LPTSTR lpBuffer,     // path buffer
  LPTSTR *lpFilePart   // address of file name in path
);
获取文件的完整路径,需要提醒的是:只有当该文件在当前目录下,结果才正确。如果要得到真正的路径。应该用GetModuleFileName函数。
  DWORD GetModuleFileName(
  HMODULE hModule,    // handle to module
  LPTSTR lpFilename// path buffer
  DWORD nSize         // size of buffer
);

  hModule HMODULE 装载一个程序实例的句柄。如果该参数为NULL,该函数返回该当前应用程序全路径。

   lpFileName LPTSTR 是你存放返回的名字的内存块的指针,是一个输出参数 nSize DWORD ,装载到缓冲区lpFileName的最大值

如果返回为成功,将在lpFileName的缓冲区当中返回相应模块的路径,如果所为的nSize过小,哪么返回仅按所设置缓冲区大小返回相应字符串内容。如果函数失败,返回值将为0,并返回GetLastError异常代码。

  DWORD GetModuleFileNameEx(
  HANDLE hProcess,    // handle to process
  HMODULE hModule,    // handle to module
  LPTSTR lpFilename// path buffer
  DWORD nSize         // maximum characters to retrieve
);
与上一个函数的不同在于多了一个与进程相关的句柄,如果为NULL则lpFilename的值为当前程序的全路径。
  DWORD GetTempPath(
  DWORD nBufferLength// size of buffer
  LPTSTR lpBuffer       // path buffer
);
获取Windows临时文件路径。
  UINT GetTempFileName(
  LPCTSTR lpPathName,      // directory name
  LPCTSTR lpPrefixString// file name prefix
  UINT uUnique,            // integer
  LPTSTR lpTempFileName    // file name buffer
);
在Windows临时目录下创建一个唯一的临时文件。具体参数信息参考MSDN。
 
 
WINSHELLAPI DWORD WINAPI SHGetFileInfo(
LPCTSTR pszPath, 
DWORD dwFileAttributes, 
SHFILEINFO FAR *psfi, 
UINT cbFileInfo, 
UINT uFlags );
获取系统文件信息,如文件,文件夹,目录,驱动器目录

 pszPath 参数:指定的文件名。

  当uFlags的取值中不包含 SHGFI_PIDL时,可直接指定;

  当uFlags的取值中包含 SHGFI_PIDL时pszPath要通过计算获得,不能直接指定;

  dwFileAttributes参数:文件属性。

  仅当uFlags的取值中包含SHGFI_USEFILEATTRIBUTES时有效,一般不用此参数;

  psfi 参数:返回获得的文件信息,是一个记录类型,有以下字段:

  _SHFILEINFOA = record

  hIcon: HICON; { out: icon } //文件的图标句柄

  iIcon: Integer; { out: icon index } //图标的系统索引号

  dwAttributes: DWORD; { out: SFGAO_ flags } //文件的属性值

  szDisplayName: array [0..MAX_PATH-1] of AnsiChar; { out: display name (or path) } //文件的显示名

  szTypeName: array [0..79] of AnsiChar; { out: type name } //文件的类型名

  end;

  cbFileInfo 参数:psfi的比特值;

  uFlags 参数:指明需要返回的文件信息标识符,常用的有以下常数:

  SHGFI_ICON; //获得图标

  SHGFI_DISPLAYNAME; //获得显示名

  SHGFI_TYPENAME; //获得类型名

  SHGFI_ATTRIBUTES; //获得属性

  SHGFI_LARGEICON; //获得大图标

  SHGFI_SMALLICON; //获得小图标

  SHGFI_PIDL; // pszPath是一个标识符

  函数SHGetFileInfo()的返回值也随uFlags的取值变化而有所不同。

  可见通过调用SHGetFileInfo()可以由psfi参数得到文件的图标句柄。但要注意在uFlags参数中不使用SHGFI_PIDL时,SHGetFileInfo()不能获得“我的电脑”等虚似文件夹的信息。

  应该注意的是,在调用SHGetFileInfo()之前,必须使用 CoInitialize 或者OleInitialize 初始化COM,否则表面上能够使用,但是会造成不安全或者丧失部分功能

6. 文件拷贝、删除、移动

  BOOL CopyFile(
  LPCTSTR lpExistingFileName, // name of an existing file
  LPCTSTR lpNewFileName,      // name of new file
  BOOL bFailIfExists          // operation if file exists
);
 
  BOOL CopyFileEx(
  LPCTSTR lpExistingFileName,           // name of existing file
  LPCTSTR lpNewFileName,                // name of new file
  LPPROGRESS_ROUTINE lpProgressRoutine, // callback function
  LPVOID lpData,                        // callback parameter
  LPBOOL pbCancel,                      // cancel status
  DWORD dwCopyFlags                     // copy options
);

文件拷贝函数,CopyFileEx函数附加功能是允许指定一个回调函数,在拷贝过程中,函数每拷贝完一部分数据,就会调用回调函数,回调函数则可由用户指定操作。

  BOOL DeleteFile(
  LPCTSTR lpFileName   // file name
);

文件删除函数,当文件不存在或者文件属性为只读,函数会执行失败,对于只读文件,在删除前就去掉其只读属性。用DeleteFile函数删除的文件不会被放到回收站,它们将永远丢失。

  BOOL MoveFile(
  LPCTSTR lpExistingFileName, // file name
  LPCTSTR lpNewFileName       // new file name
);
  BOOL MoveFileEx(
  LPCTSTR lpExistingFileName// file name
  LPCTSTR lpNewFileName,       // new file name
  DWORD dwFlags                // move options
);

文件移动函数,其主要功能都是用来移动一个存在的文件或目录,当需要指定文件如何移动时,则用MoveFileEx函数,其dwFlags指定文件移动方式,具体说明可参考MSDN。

7. 文件查找

  HANDLE FindFirstFile(
  LPCTSTR lpFileName,               // file name
  LPWIN32_FIND_DATA lpFindFileData  // data buffer
);
  HANDLE FindFirstFileEx(
  LPCTSTR lpFileName,              // file name
  FINDEX_INFO_LEVELS fInfoLevelId, // information level
  LPVOID lpFindFileData,           // information buffer
  FINDEX_SEARCH_OPS fSearchOp,     // filtering type
  LPVOID lpSearchFilter,           // search criteria
  DWORD dwAdditionalFlags          // reserved
);

该函数到一个文件夹(包括子文件夹)去搜索指定文件 如果要使用附加属性去搜索文件的话 可以使用FindFirstFileEx函数。HANDLE hFindFile搜索的文件句柄 函数执行的时候搜索的是此句柄的下一文件

  LPWIN32_FIND_DATA lpFindFileData 指向一个用于保存文件信息的结构体

函数调用成功后,其返回值可用作FindNextFile或FindClose函数的参数。

  BOOL FindNextFile(
  HANDLE hFindFile,                // search handle
  LPWIN32_FIND_DATA lpFindFileData // data buffer
);

在FindFirstFile函数调用成功后继续查找文件。

8. 压缩文件操作

  INT LZOpenFile(
  LPTSTR lpFileName,       // file name
  LPOFSTRUCT lpReOpenBuf// file information buffer
  WORD wStyle              // action to take
);

创建,打开,删除压缩文件。参数信息参考MSDN。

  VOID LZClose(
  INT hFile   // LZ file handle
);

关闭压缩文件,参数为LPOpenFile返回的值。

  LONG LZCopy(
  INT hfSource// LZ file handle for source file
  INT hfDest     // LZ file handle for destination file
);

复制压缩文件并在处理过程中展开,函数的两个参数都可以用LPOpenFile函数得到,只要指定LPOpenFile函数wStyle的不同值。

INT GetExpandedName(
  LPTSTR lpszSource// name of compressed file
  LPTSTR lpszBuffer   // original file name
);

从压缩文件中返回文件名称,参数信息参考MSDN。

Categories
爪机爪机

[ROM](5.6.24) Team Venom ViperDNA 1.3.0a l Tweaks l EQS l HUB l 均衡器 l SideBar

http://lt.imobile.com.cn/forum.php?mod=viewthread&tid=10350986&extra=page%3D1

 
venom_banner

Categories
不学无术

Python如何遍历一个文件夹下的所有文件

import glob
fileList=glob.glob(“E:PythonWork*.exe”)
for filename in fileList:
带参数调用filename
 
 
source:
http://bbs.csdn.net/topics/90198608

Categories
木有技术

sublime text2 配置tab为4个空格

Preference-defalut:
【将Tab键自动替换为4个空格】
// The number of spaces a tab is considered equal to
“tab_size”: 4,
// Set to true to insert spaces when tab is pressed
“translate_tabs_to_spaces”: true,

Categories
不学无术

Lex与Yacc快速入门

附件:Yacc与Lex快速入门
http://orz.dayandcarrot.net/wordpress/wp-content/uploads/2013/05/Yacc与Lex快速入门.pdf
 
Lex 和 Yacc 是 UNIX 两个非常重要的、功能强大的工具。事实上,如果你熟练掌握
Lex 和 Yacc 的话,它们的强大功能使创建 FORTRAN 和 C 的编译器如同儿戏。
Ashish Bansal 为您详细的讨论了编写自己的语言和编译器所用到的这两种工具,包
括常规表达式、声明、匹配模式、变量、Yacc 语法和解析器代码。最后,他解释了
怎样把 Lex 和 Yacc 结合起来。
详见附件