C++ Project

1. Right click the Project, click `Properties`
2. Navigate to `Linker`
3. Navigate to `Manifest File`
4. Edit the `UAC Execution Level` to `requireAdministrator`

C# project:

Edit the properties\app.manifest, modify the permission node as the one in the specifications there.

Debug with UAC:

Start the VisualStudio with Administrator permission, and you can debug the projects need UAC.

```    for (int alreadyRead = 0; alreadyRead < len; )
```

```<p class="aClass">some content</p>
```

```element.getAttribute("class");
```

```element.getAttribute("className");
```

LeetCode题目：Merge k Sorted Lists

Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.

logk

```/**
* struct ListNode {
*     int val;
*     ListNode *next;
*     ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) {
ListNode *proot = NULL;
ListNode **pplast = &proot;
while(l1 || l2){
if(l1) {
ListNode *minNode;
if(!l2 || l1->val <= l2->val){
//l1 is min
minNode = l1;
l1 = l1->next;
} else if(l2) {
//l2 is min
minNode = l2;
l2 = l2->next;
}
//proceed root
*pplast = minNode;
pplast = &(minNode->next);
} else {
//l1 is empty
*pplast = l2;
break;
}
}
return proot;
}
ListNode *mergeKLists(vector &lists) {
if(lists.size() == 0)
return NULL;
int curSize = lists.size();
while(curSize > 1) {
int halfSize = (1 + curSize) / 2;
//merge i,i + halfSize
for(int i = 0 ; i < halfSize && i + halfSize < curSize; ++i) {
ListNode *first = lists[i];
ListNode *second = lists[i + halfSize];
ListNode *result = mergeTwoLists(first,second);
lists[i] = result;
}
//set curSize to halfsize
curSize = halfSize;
}
return lists[0];
}
};
```

POJ1002 Phone Number Duplication

1.gets()比cin()快
2.cin()不自动吃掉’\n’，需要的话，用getchar()吃掉
3.printf(“%.3d”,anInt)，不足3位在前面补0
4.时间问题，抓主要矛盾（线性搜索改为二叉树搜索），new操作都是次要的，链表比数组慢也是次要的

<

// main.cpp
// POJ1002-PhoneNumberDuplication
// Created by Qiu Xiangyu on 12-7-10.
// gets()比cin()快
// cin()不自动吃掉’\n’，需要的话，用getchar()吃掉
// printf(“%.3d”,anInt)，不足3位在前面补0
// 时间问题，抓主要矛盾（线性搜索改为二叉树搜索），new操作都是次要的，链表比数组慢也是次要的

include

//#include
using namespace std;

struct node{
long phoneNumber;
int repeatCount;
node leftChild;
node *rightChild;
node *parant;
};
inline int translateCode(char c)
{
if (c >= ‘0’ && c <= ‘9’) {
return c – ‘0’;
}
if (c >= ‘A’ && c <= ‘O’) {
int num = c – ‘A’;
return num / 3 + 2;
}
if (c == ‘P’ || c == ‘R’ || c == ‘S’) {
return 7;
}
if (c >= ‘T’ && c <= ‘V’) {
return 8;
}
if (c >= ‘W’ && c <= ‘Y’) {
return 9;
}
return -1;
}
inline node *findNodeWithNumber(node
startNode, long number)
{
if (startNode == NULL) {
return NULL;
}
if (startNode->phoneNumber == number) {
return startNode;
} else if (startNode->phoneNumber < number) {
if (startNode->rightChild == NULL) {
return startNode;
}
return findNodeWithNumber(startNode->rightChild, number);
} else {
if (startNode->leftChild == NULL) {
return startNode;
}
return findNodeWithNumber(startNode->leftChild, number);
}
}
bool haveDuplication = false;
inline void output(node *root)
{
if (root == NULL) {
return;
}
output(root->leftChild);

```if (root->repeatCount > 1) {
haveDuplication = true;
long phoNum = root->phoneNumber;
int first = phoNum / 10000;
int last = phoNum % 10000;
printf("%.3d-%.4d %d\n",first,last,root->repeatCount);
}

output(root->rightChild);```

}
int main(int argc, const char * argv[])
{
int totalNumber;
cin>>totalNumber;
getchar();
// cout<<“total:”<<totalNumber<<endl;
for (int iNumber = 0; iNumber < totalNumber; iNumber ++) {
char inputbuffer[500];
char *str = inputbuffer;
gets(str);
// cout<<aNumber<<endl;
// cout<<str;
long phoneNumber = 0;
int strLen = strlen(str);// aNumber.length();
// if (strLen == 0) {
// iNumber–;
// continue;
// }
for (int ichar = 0; ichar < strLen; ichar ++) {
char c = str[ichar];
if (c == ‘-‘) {
continue;
}
int num = translateCode(c);
if (num == -1) {
continue;
}
phoneNumber = 10 * phoneNumber + num;
}
// cout<<phoneNumber<<endl;
if (phoneNode) {
if (phoneNode->phoneNumber == phoneNumber) {
phoneNode->repeatCount ++;
} else if (phoneNode->phoneNumber < phoneNumber) {
node *parant = phoneNode;
node *child = new node();
child->phoneNumber = phoneNumber;
child->repeatCount = 1;
child->parant = parant;
parant->rightChild = child;
} else {
node *parant = phoneNode;
node *child = new node();
child->phoneNumber = phoneNumber;
child->repeatCount = 1;
child->parant = parant;
parant->leftChild = child;
}
} else {
phoneNode = new node();
phoneNode->phoneNumber = phoneNumber;
phoneNode->repeatCount = 1;
}
}
// cout<<“done”<<endl;
if (!haveDuplication) {
cout<<“No duplicates.”<<endl;
}
return 0;
}

通过javascript控制flash

1. function getSWF(a){
2.   if(navigator.appName.indexOf(\”Microsoft\”)!=-1){
3.     return window[a];
4.   } else {
5.     if(window.navigator.userAgent.indexOf(\”Firefox\”)!=-1){
6.       return document[a];
7.     } else {
8.       if(window.navigator.userAgent.indexOf(\”Chrome\”)!=-1){
9.         return document[a];
10.       } else {
11.         if(window.navigator.userAgent.indexOf(\”Safari\”)!=-1){
12.           return document.getElementById(a);
13.         } else {
14.           if(window.navigator.userAgent.indexOf(\”Opera\”)!=-1){
15.             return document[a];
16.           }
17.         }
18.       }
19.     }
20.   }
21. }
1. flash=getSWF(‘flashName’);

1. flash.function();

C#中让WebBrowser运行Javascript脚本

C#中可以让Webbrowser运行Javascript脚本来实现各种自动化操作，比如点击网页上的按钮，输入用户名密码等等。代码也很简单：

>>>>>>>>>>>>>>>>>>>>方法一：

1.             HtmlElement btn = webBrowser1.Document.GetElementById(“aBtn”);
2.             if (btn != null)
3.                 btn.InvokeMember(“click”);

>>>>>>>>>>>>>>>>>>>>方法二：

1. HtmlElement ele = webBrowser1.Document.CreateElement(“script”);
2. ele.SetAttribute(“type”, “text/javascript”);
3. ele.SetAttribute(“text”, “someJavaScript”);
4. webBrowser1.Document.Body.AppendChild(ele);

>>>>>>>>>>>>>>>>>>>>方法三：

1. webBrowser1.Document.InvokeScript(“someInPageJavaFunction”, null);

>>>>>>>>>>>>>>>>>>>>另外：