ftp
samba
scp
copy file 'testfile' to remote linux.
scp testfile jian@172.17.92.240:/home/jian
scp -P 2200 testfile jian@172.17.92.240:/home/jian
testfile 和 -P 2200 的位置不能对掉,有点坑
#include <stdio.h>
int main()
{
printf("%c\n", "abcdef"[5]);
printf("%c\n", 5["abcdef"]);
char a[] = "abcdef";
char * p = a;
printf("%c\n", 5[a]);
printf("%c\n", a[5]);
printf("%c\n", 5[p]);
printf("%c\n", p[5]);
printf("%c\n", *(p+5));
printf("%c\n", *(5+p));
return 0;
}
#include <stdio.h>
#define SIZE 3
int main()
{
printf("demo\n");
int valida[SIZE] = {0, 1, 2, };
int a[SIZE] = {0, 1, 2};
int * pi = a;
int (*pa)[SIZE] = &a;
int i = 0;
for (i = 0; i < SIZE; i++)
{
printf("a[%d] = %d\t", i, a[i]);
}
printf("\n");
for (i = 0; i <= SIZE; i++)
{
printf("%p\t", &a[i]);
}
printf("\n");
for (i = 0; i < SIZE; i++)
{
printf("*(a+%d) = %d\t", i, *(a+i) );
}
printf("\n");
for (i = 0; i < SIZE; i++)
{
printf("*(pi+%d) = %d\t", i, *(pi+i) );
}
printf("\n");
printf("sizeof(a) = %d\n", sizeof(a));
printf("sizeof(pi) = %d\n\n", sizeof(pi));
printf("a = %p\n", a);
printf("pi = %p\n", pi);
printf("&a = %p\n", &a);
printf("pa = %p\n", pa);
printf("a+1 = %p\n", a+1);
printf("pi+1 = %p\n", pi+1);
printf("&a + 1 = %p\n", &a + 1);
printf("pa + 1 = %p\n", pa + 1);
return 0;
}
直接重启程序。简单,好用。
隐藏主界面,显示登录界面。登录成功就隐藏登录界面,显示主界面。
这种方法会有很多的中间变量状态要清空,非常麻烦,几乎无法使用,因此不建议使用。
https://leetcode.com/problems/populating-next-right-pointers-in-each-node/description/
Given a binary tree
struct TreeLinkNode {
TreeLinkNode *left;
TreeLinkNode *right;
TreeLinkNode *next;
}
Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL.
Initially, all next pointers are set to NULL.
Note:
For example,
Given the following perfect binary tree,
1
/ \
2 3
/ \ / \
4 5 6 7
After calling your function, the tree should look like:
1 -> NULL
/ \
2 -> 3 -> NULL
/ \ / \
4->5->6->7 -> NULL
/**
* Definition for binary tree with next pointer.
* struct TreeLinkNode {
* int val;
* TreeLinkNode *left, *right, *next;
* TreeLinkNode(int x) : val(x), left(NULL), right(NULL), next(NULL) {}
* };
*/
class Solution {
public:
void connect(TreeLinkNode *root) {
if(NULL == root) {
return ;
}
queue<TreeLinkNode *> nodeQueue;
nodeQueue.push(root);
m_vConnect(nodeQueue);
}
void m_vConnect(queue<TreeLinkNode *> & nodeQueue)
{
if(nodeQueue.empty()) {
return ;
}
TreeLinkNode * pTail = NULL;
int iCurSize = nodeQueue.size();
for (int i = 0; i < iCurSize; i++)
{
TreeLinkNode * pNode = nodeQueue.front();
nodeQueue.pop();
if(pNode->left != NULL)
{
nodeQueue.push(pNode->left);
nodeQueue.push(pNode->right);
}
if(i == 0)
{
pTail = pNode;
}
else
{
pTail->next = pNode;
pTail = pNode;
}
}
m_vConnect(nodeQueue);
}
};
#include <stdio.h>
int main()
{
int i;
int c;
unsigned char ucAscii[256] = {0};
while ( (c = getchar()) != EOF )
{
if(c >= 0 && c < 256)
{
ucAscii[c]++;
}
}
for (i = 0; i < 256; i++)
{
printf("(%d|%c):[%d]\n", i, (unsigned char)i, ucAscii[i]);
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_WORD_NUM 10000
typedef struct _SWord
{
char m_acWord[BUFSIZ];
int m_iCount;
}SWord;
SWord g_acWord[MAX_WORD_NUM] = {0};
int g_iWordIndex = 0;
int main()
{
int i;
int bExists;
char acWord[BUFSIZ] = {0};
while (scanf("%s", acWord) != EOF)
{
bExists = 0;
for (i = 0; i < g_iWordIndex; i++)
{
if(strcmp(g_acWord[i].m_acWord, acWord) == 0)
{
bExists = 1;
g_acWord[i].m_iCount++;
break;
}
}
if(!bExists)
{
strncpy(g_acWord[g_iWordIndex].m_acWord, acWord, BUFSIZ);
g_acWord[g_iWordIndex].m_iCount = 1;
g_iWordIndex++;
}
}
for (i = 0; i < g_iWordIndex; i++)
{
printf("%s:[%d]\n", g_acWord[i].m_acWord, g_acWord[i].m_iCount);
}
return 0;
}
这是用数组来保存的,需要遍历整个数组,效率不高。
换成 hash表 或者 红黑树 可以提高效率。
最后给一个C++的实现。
#include <iostream>
#include <string>
#include <map>
#include <stdio.h>
using namespace std;
int main()
{
char acWord[BUFSIZ] = {0};
map<string, int> wordmap;
while (scanf("%s", acWord) != EOF)
{
string strWord = acWord;
map<string, int>::iterator iter = wordmap.find(strWord);
if(iter == wordmap.end())
{
wordmap.insert( std::pair<string, int>(strWord, 1) );
}
else
{
iter->second++;
}
}
map<string, int>::iterator iter = wordmap.begin();
while (iter != wordmap.end())
{
printf("%s[%d]\n", const_cast<char*>(iter->first.c_str()), iter->second);
++iter;
}
return 0;
}