#
這道題我用的方法很麻煩,使用一個結構體vector保存結果,使用一個map判斷是不是一個人報了兩個工程.使用set判斷一個工程是不是有人重復報名
于是就有了下面的笨拙代碼
1
#include <string>
2
#include <set>
3
#include <vector>
4
#include <memory.h>
5
#include <map>
6
#include <algorithm>
7
using namespace std;
8
9
struct Project
10

{
11
string name;
12
int studentcount;
13
Project()
14
{
15
studentcount=0;
16
name.assign("");
17
}
18
};
19
20
map<string,int> studentmap;
21
set<string> studentset;
22
vector<Project> prov;
23
int countarray[101]=
{0};
24
char strtemp[100]="";
25
Project project;
26
27
inline bool comp(const Project &p1,const Project &p2)
28

{
29
return p1.studentcount>p2.studentcount;
30
}
31
inline bool comp2(const Project &p1,const Project &p2)
32

{
33
return p1.name.compare(p2.name)<0;
34
}
35
36
int main()
37

{
38
39
while(true)
40
{
41
int projcount=0;
42
prov.push_back(project);
43
while(true)
44
{
45
gets(strtemp);
46
project.name.assign(strtemp);
47
if(project.name[0]=='1')break;
48
if(project.name[0]=='0')exit(0);
49
if(project.name[0]>='A'&&project.name[0]<='Z')
50
{
51
prov.push_back(project);
52
studentset.clear();
53
projcount++;
54
}
55
if(project.name[0]>='a'&&project.name[0]<='z')
56
{
57
if(studentmap[strtemp]==0)
58
{
59
studentmap[strtemp]=projcount;
60
}
61
else if(studentmap[strtemp]==-1)
62
{
63
continue;
64
}
65
else if(studentmap[strtemp]!=projcount)
66
{
67
prov[studentmap[strtemp]].studentcount--;
68
studentmap[strtemp]=-1;
69
continue;
70
}
71
if(studentset.count(strtemp))
72
continue;
73
else
74
{
75
studentset.insert(strtemp);
76
prov[projcount].studentcount++;
77
}
78
}
79
}
80
prov.erase(prov.begin());
81
stable_sort(prov.begin(),prov.end(),comp2);
82
stable_sort(prov.begin(),prov.end(),comp);
83
for(int i=0;i<prov.size();i++)
84
{
85
printf("%s %d\n",prov[i].name.c_str(),prov[i].studentcount);
86
}
87
memset(countarray,0,sizeof(countarray));
88
studentmap.clear();
89
prov.clear();
90
91
}
92
}
93
94
我的做法可能很弱智
給定一個數x>0算通過每一位零出現次數的統計,算出所有的0的次數(從1到X)
舉一個例子
2508這個數
首先考慮個位數
250X X=0;一共有250-1+1個
25X8 X=0;一共有258-10+1個
2X08 X=0;注意并不只有208-100+1中可能,我之前就錯在這里了,因為最大2508,所以2099-2009這百位的零我就沒有考慮到,所以這里的0有299-100+1個
于是題目就做出來了
輸入一個a b
a<b
a==0時
b統計出零的個數然后加1(0)的個數
否則從a 到 b的0的個數則是從1到b的0個數減去從1到a-1的零的個數
a<10的情況我害怕出錯就分開寫了,所以整個程序有些長
下面就是我笨拙的代碼
1
#include <iostream>
2
#include <string>
3
#include <cstdio>
4
#include <cstdlib>
5
#include <cmath>
6
using namespace std;
7
long long aarray[10]=
{0};
8
long long barray[10]=
{0};
9
long long diff[10]=
{0};
10
char tempstr[10] = "";
11
12
13
int calc(std::string str,int i)
14

{
15
//str.erase()
16
if(i==(str.size()-1)) return 0;
17
long long sum=0,len=str.size();
18
int needminus = int(pow(10.0,i));
19
//if(i!=0)str[len-i-2]+=(str[len-i-1]-'0');//new add
20
if(str[len-i-1]=='0')
21
{
22
str.erase(len-i-1,1);
23
}
24
else
25
{
26
str.erase(len-i-1,i+1);
27
str.append(i,'9');
28
}
29
for(int i=0;i<str.size();i++)
30
{
31
sum=sum*10+(str[i]-'0');
32
}
33
sum-=needminus;
34
sum+=1;
35
return sum;
36
}
37
38
int main()
39

{
40
unsigned int a,b;
41
std::string tempstring;
42
int add;
43
while(scanf("%u %u",&a,&b))
44
{
45
add=0;
46
47
if(a==0)
48
add=1;
49
else
{
50
add=0;
51
a--;
52
}
53
if(a==-2)
54
break;
55
int alen,blen;
56
if(a<10)
57
{
58
aarray[0]=0;
59
}
60
else
61
{
62
_i64toa(a,tempstr,10);
63
alen = strlen(tempstr);
64
tempstring.assign(tempstr);
65
for(int i=0;i<alen;i++)
66
{
67
aarray[i]=calc(tempstring,i);
68
}
69
}
70
_i64toa(b,tempstr,10);
71
blen = strlen(tempstr);
72
tempstring.assign(tempstr);
73
for(int i=0;i<blen;i++)
74
{
75
barray[i]=calc(tempstring,i);
76
}
77
for(int i=0;i<blen;i++)
78
{
79
diff[i]=barray[i]-aarray[i];
80
}
81
long long sum=0;
82
for(int i=0;i<blen;i++)
83
{
84
sum+=diff[i];
85
}
86
87
cout<<sum+add<<endl;
88
memset(aarray,0,sizeof(long long)*10);
89
memset(barray,0,sizeof(long long)*10);
90
memset(diff,0,sizeof(long long)*10);
91
}
92
}
基本沒做什么
喝光了一箱健力寶,吃掉了許多娃娃臉,吃了幾次羊,對travian這個網頁游戲做了提供輔助的可行性測試,借此了解更多了些webbrowswer控件及其周邊,同學什么都沒怎么見,唉,估計只能等到寒假了...
回到學校,爭取這周給輔助做的差不多,別的也不能落下
...
...
99塊

太懶了.看書有如在堆棧,都快滿棧了...
假期打算根據那本Mud Programming模仿著寫個mud..
#define SubclassWindow(hwnd, lpfn) \
((WNDPROC)SetWindowLongPtr((hwnd), GWLP_WNDPROC, (LPARAM)(WNDPROC)(lpfn)))
這個宏是我看第七章winshellprograming看到的,很強大的功能,例子是用FindWindowEx找到windows開始按鈕的窗口句柄,之后用該宏加入開始按鈕的消息處理函數.總之還不錯,winshell還真不是一般..
MSDN上查SubclassWindow都不是我要的這個,雖然功能大體相同吧.
下面這個就是SetWindowLongPtr函數:
SetWindowLongPtr Function
The SetWindowLongPtr function changes an attribute of the specified window. The function also sets a value at the specified offset in the extra window memory.
這個函數改變一個指定窗口的一個屬性.它也可設定窗口儲存區指定偏移位置的值。
This function supersedes the SetWindowLong function. To write code that is compatible with both 32-bit and 64-bit versions of Microsoft Windows, use SetWindowLongPtr.
這個函數取代了SetWindowLong函數,為了兼容32位64位windows os,就用這個函數吧 .
Syntax
LONG_PTR SetWindowLongPtr(
HWND hWnd,
int nIndex,
LONG_PTR dwNewLong
);
Parameters
- hWnd
- [in] Handle to the window and, indirectly, the class to which the window belongs. The SetWindowLongPtr function fails if the process that owns the window specified by the hWnd parameter is at a higher process privilege in the User Interface Privilege Isolation (UIPI) hierarchy than the process the calling thread resides in.
- 返回fail當擁有指定窗口的京城比用戶UI權限隔絕(??)高的時候..不知道翻譯對不
-
Microsoft Windows XP and earlier: The SetWindowLongPtr function fails if the window specified by the hWnd parameter does not belong to the same process as the calling thread.
這個意思大概是函數失敗如果調用進程傳入的hWnd句柄不屬于調用包含這個函數的線程的進程(應用程序).
- nIndex
- [in] Specifies the zero-based offset to the value to be set. Valid values are in the range zero through the number of bytes of extra window memory, minus the size of an integer. To set any other value, specify one of the following values.
- 這個不用翻譯了,很明了哈哈
-
-
-
GWL_EXSTYLE
- Sets a new extended window style. For more information, see CreateWindowEx.
GWL_STYLE
- Sets a new window style.
GWLP_WNDPROC
- Sets a new address for the window procedure.
GWLP_HINSTANCE
- Sets a new application instance handle.
GWLP_ID
- Sets a new identifier of the window.
GWLP_USERDATA
- Sets the user data associated with the window. This data is intended for use by the application that created the window. Its value is initially zero.
-
- The following values are also available when the hWnd parameter identifies a dialog box.
DWLP_DLGPROC
- Sets the new pointer to the dialog box procedure.
DWLP_MSGRESULT
- Sets the return value of a message processed in the dialog box procedure.
DWLP_USER
- Sets new extra information that is private to the application, such as handles or pointers.
- dwNewLong
- [in] Specifies the replacement value.
Return Value
If the function succeeds, the return value is the previous value of the specified offset.
成功返回的是設置前的值LONG_PTR這個類型
If the function fails, the return value is zero. To get extended error information, call GetLastError.
If the previous value is zero and the function succeeds, the return value is zero, but the function does not clear the last error information. To determine success or failure, clear the last error information by calling SetLastError(0), then call SetWindowLongPtr. Function failure will be indicated by a return value of zero and a GetLastError result that is nonzero.
Remarks
Certain window data is cached, so changes you make using SetWindowLongPtr will not take effect until you call the SetWindowPos function.
If you use SetWindowLongPtr with the GWLP_WNDPROC index to replace the window procedure, the window procedure must conform to the guidelines specified in the description of the WindowProc callback function.
If you use SetWindowLongPtr with the DWLP_MSGRESULT index to set the return value for a message processed by a dialog box procedure, the dialog box procedure should return TRUE directly afterward. Otherwise, if you call any function that results in your dialog box procedure receiving a window message, the nested window message could overwrite the return value you set by using DWLP_MSGRESULT.
Calling SetWindowLongPtr with the GWLP_WNDPROC index creates a subclass of the window class used to create the window. An application can subclass a system class, but should not subclass a window class created by another process. The SetWindowLongPtr function creates the window subclass by changing the window procedure associated with a particular window class, causing the system to call the new window procedure instead of the previous one. An application must pass any messages not processed by the new window procedure to the previous window procedure by calling CallWindowProc. This allows the application to create a chain of window procedures.
Reserve extra window memory by specifying a nonzero value in the cbWndExtra member of the WNDCLASSEX structure used with the RegisterClassEx function.
Do not call SetWindowLongPtr with the GWLP_HWNDPARENT index to change the parent of a child window. Instead, use the SetParent function.
If the window has a class style of CS_CLASSDC or CS_PARENTDC, do not set the extended window styles WS_EX_COMPOSITED or WS_EX_LAYERED.
Windows XP/Vista: Calling SetWindowLongPtr to set the style on a progressbar will reset its position.
Function Information
先到這里,以后會寫更多Win32的基礎知識,當我學到的時候..
btw,有本叫the old new thing 似乎很強,不知道什么時候能有一本...
輸入a,n,k(1<=a,n<=1e9 1<=k<=10000 ,注意:有多組測試數據,請用EOF標志判斷結束輸入):
2 32 5
2 30 5
輸出(a^n)%k的結果(a的n次方被k除的余數):
輸入a,n,k(1<=a,n<=1e9 1<=k<=10000 ,注意:有多組測試數據,請用EOF標志判斷結束輸入):
2 32 5
2 30 5
輸出(a^n)%k的結果(a的n次方被k除的余數):
要求復雜度為O(logn)
解決思路,吃屎兄的推導的
(a*b)Mod c=((a Mod c)*b)Mod c
a^b Mod c 把B寫成二進制(At ,At-1,At-2...A1,A0)
a^b Mod c =(a^(At*2^t....A0*2^0)mod c)=
((a^A0*2^0 mod c)*a^A1*2^1mod c).....
t=log2B;
下面是小弟的程序
#include <iostream>
using namespace std;
int convertToBin(int n,int (&arr)[14])


{
int i=0;
while(n)

{
arr[i]=n%2;
n=n/2;
i++;
}
return i;
}
int findAnswer(int k,int a,int arr[14],int bsize)


{
int ret = 1;
for(int i=0;i<bsize;i++)

{
if(arr[i])
ret=(ret*a*(1<<i))%k;
else
ret=(ret*(1<<i))%k;
}
return ret;
}
int main()


{
int a,n,k=1;
while(!cin.eof())

{
cin>>a;
if(a==-1) break;
cin>>n>>k;

int arr[14]=
{0};
int bsize = convertToBin(n,arr);
cout<<findAnswer(k,a,arr,bsize)<<endl;
}
}
這章用到比較多的兩個接口
IShellLink IPersistFile
兩個COM接口,一個ShellLink提供對于快捷方式信息存取的方法,但是如果要載入或保存快捷方式,需要通過ShellLink Query一個IPersistFile接口,使用IPersistFile的載入保存方法.
貼載入與讀取的這段
1
WCHAR wszLnkFile[MAX_PATH] =
{0};
2
IShellLink* pShellLink = NULL;
3
IPersistFile* pPF = NULL;
4
5
// Create the appropriate COM server
6
HRESULT hr = CoCreateInstance(CLSID_ShellLink, NULL,
7
CLSCTX_INPROC_SERVER, IID_IShellLink,
8
reinterpret_cast<LPVOID*>(&pShellLink));
9
if(FAILED(hr))
10
return hr;
11
12
// Get the IPersistFile interface to load the LNK file
13
hr = pShellLink->QueryInterface(IID_IPersistFile, reinterpret_cast<LPVOID*>(&pPF));
14
if(FAILED(hr))
15
{
16
pShellLink->Release();
17
return hr;
18
}
19
MultiByteToWideChar(CP_ACP, 0, szLnkFile, -1, wszLnkFile, MAX_PATH);
20
hr = pPF->Load(wszLnkFile, STGM_READ);
21
if(FAILED(hr))
22
{
23
pPF->Release();
24
pShellLink->Release();
25
return hr;
26
}
27
28
//現在可以用pShellLink了
29
hr = pPF->Save(wszLnkFile, TRUE);
30
31
// Clean up
32
pPF->Release();
33
pShellLink->Release();
34
下面這段是一個Drag的例子
WindowFromPoint(pt)感覺很強,可以獲取pt點(屏幕坐標系)的窗體對象
DragQueryFile來分析hDrop
hDrop是WM_DROPFILES事件的(wParam)參數,類型為HDROP
一般都用reinterpret_cast轉換
POINT pt;
DragQueryPoint(hDrop, &pt);
ClientToScreen(hDlg, &pt);
HWND hwndDrop = WindowFromPoint(pt);
if(hwndDrop != GetDlgItem(hDlg, IDC_VIEW))

{
Msg(__TEXT("Sorry, you have to drop over the list view control!"));
return;
}

// Now check the files
int iNumOfFiles = DragQueryFile(hDrop, -1, NULL, 0);
for(int i = 0 ; i < iNumOfFiles; i++)

{

TCHAR szFileName[MAX_PATH] =
{0};
DragQueryFile(hDrop, i, szFileName, MAX_PATH);
//獲得了文件名,index為i的
}

DragFinish(hDrop);



看 VC++Win Shell Programming
對win32 編程有點體會
了解了一些HIMAGELIST 這個win32結構
很多ImageList_XXX函數
還有就是IShellFolder這個接口
LPSHELLFOLDER
有很多SHXX函數用
今天來再更新一點
IShellFolder Interface 接口的成員
The IShellFolder interface is used to manage folders. It is exposed by all Shell namespace folder objects.
IShellFolder Members
BindToObject |
Retrieves an IShellFolder object for a subfolder.書上有講 |
BindToStorage |
Requests a pointer to an object's storage interface. |
CompareIDs |
Determines the relative order of two file objects or folders, given their item identifier lists. |
CreateViewObject |
Requests an object that can be used to obtain information from or interact with a folder object. |
EnumObjects |
Allows a client to determine the contents of a folder by creating an item identifier enumeration object and returning its IEnumIDList interface. The methods supported by that interface can then be used to enumerate the folder's contents.下面有IEnumIDList的成員 |
GetAttributesOf |
Retrieves the attributes of one or more file or folder objects contained in the object represented by IShellFolder. |
GetDisplayNameOf |
Retrieves the display name for the specified file object or subfolder. 書上有講 |
GetUIObjectOf |
Retrieves an OLE interface that can be used to carry out actions on the specified file objects or folders.書上有講 |
ParseDisplayName |
Translates a file object's or folder's display name into an item identifier list.書上有講 |
SetNameOf |
Sets the display name of a file object or subfolder, changing the item identifier in the process. |
IEnumIDList Interface
The IEnumIDList interface provides a standard set of methods that can be used to enumerate the pointers to item identifier lists (PIDLs) of the items in a Shell folder. When a folder's IShellFolder::EnumObjects method is called, it creates an enumeration object and passes a pointer to the object's IEnumIDList interface back to the caller.
IEnumIDList Members
Clone |
Creates a new item enumeration object with the same contents and state as the current one. |
Next |
Retrieves the specified number of item identifiers in the enumeration sequence and advances the current position by the number of items retrieved. |
Reset |
Returns to the beginning of the enumeration sequence. |
Skip |
Skips over the specified number of elements in the enumeration sequence. |