1、操作进程:
private bool CloseProcess(string CloseProcessName) { try { //根据进程名称,获取该进程信息 Process[] MyProcessS = Process.GetProcessesByName(CloseProcessName); foreach (Process MyProcess in MyProcessS) { MyProcess.Kill(); MyProcess.WaitForExit(); MyProcess.Close(); Thread.Sleep(10000); } } catch (Exception) { return false; } return true; } /// <summary> /// 创建进程 /// </summary> public bool StartProcess(string StartProPath) { try { Process TheStartProcess = Process.Start(StartProPath); } catch (Exception) { return false; } return true; }
2、操作服务:
private bool StopService(string StopServiceName) { ServiceController service = new ServiceController(StopServiceName); try { service.Stop(); service.WaitForStatus(ServiceControllerStatus.Stopped); } catch(Exception) { return false; } return true; } /// <summary> /// 开启服务 /// </summary> private bool StartService(string StartServiceName) { ServiceController service = new ServiceController(StartServiceName); try { service.Start(); service.WaitForStatus(ServiceControllerStatus.Running); } catch (Exception) { return false; } return true; }
3、操作注册表:
///获得注册表的值
private string GetRegistShellData(string RegistName) { try { string registData, SubregistData; RegistryKey hkml = Registry.LocalMachine; RegistryKey software = hkml.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", true); registData = software.GetValue(RegistName).ToString(); SubregistData = registData.Substring(0, 2); return SubregistData; } catch (Exception excp) { MessageBox.Show("GetRegistShellData错误" + excp.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return ""; } /// <summary>
/// </summary> ///更改注册表的值
private void RenameRegistData() { try { string registData1; RegistryKey hkml = Registry.LocalMachine; RegistryKey software2 = hkml.OpenSubKey(@"SOFTWARE\"+ Shadowin + @"\SysToolSign", true); registData1 = software2.GetValue("Sign").ToString(); software2.SetValue("Sign", "1"); registData1 = software2.GetValue("Sign").ToString(); } catch (Exception excp) { MessageBox.Show("RenameRegistData错误" + excp.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return ; }
1)‘_wcsicmp’在此作用域中尚未声明
#ifdef WIN32
#define _tcsicmp _wcsicmp
#else
#define _tcsicmp wcscasecmp
#endif
2)_stricmp 在此作用域中尚未声明
#include <string.h>
将_stricmp改成strcasecmp
3)atoi的wchar版本不存在,
#define _ttoi _wtoi
改成使用
#define _tcstol wcstol
4)_atoi64
改成
atoll
5)‘itoa’在此作用域中尚未声明 或者 ‘_itoa’在此作用域中尚未声明
改成
sprintf(buf,"%d",n);
6)‘ultoa’在此作用域中尚未声明 或者 ‘_ultoa’在此作用域中尚未声明
改成
sprintf(buf,"%ul",n);
7)‘ltoa’在此作用域中尚未声明 或者 ‘_ltoa’在此作用域中尚未声明
改成
sprintf(buf,"%l",n);
8)‘_i64toa’在此作用域中尚未声明
改成
sprintf(buf,"%lld",n);
9)htonl,htons,ntohl,ntohs 在此作用域中尚未声明
包含
#include <arpa/inet.h>
10)‘__int64’没有命名一个类型
将__int64 改为 long long
32位为ILP32(int,long,pointer为32位),64位采用LP64(long,pointer为64),其他不变
11)‘struct in_addr’没有名为‘S_un’的成员
in_addr ip;
ip.S_un.S_addr = "127.0.0.1";
将ip.S_un.S_addr改为ip.s_addr,如下:
ip.s_addr = "127.0.0.1";
12)
std::vector<InternalObj<T>* >::iterator iter = used_obj_.begin();
错误:expected ‘;’ before ‘iter’
std::vector<int> testv;
std::vector<int>::iterator iter1 = testv.begin();
以上两句语法正确。
C++规定,引用嵌套模版类的内部类型(如std::vector<T>::iterator),必须显示告诉编译器这是个type而不是variable。
例如
typename std::vector<InternalObj<T>* >::iterator iter = used_obj_.begin();
在VC或Intel Compiler中不会出现这样的问题。
但GCC编译器则会严格按照C++规定认为是个变量。
http://blog.csdn.net/tedious/article/details/6063910
13)
boost::timer
elapsed函数windows返回正确,linux下返回0
14)
‘memset’在此作用域中尚未声明
‘strlen’在此作用域中尚未声明
‘memcpy’在此作用域中尚未声明
#include <string.h>
15)
‘free’在此作用域中尚未声明
‘malloc’在此作用域中尚未声明
#include <stdlib.h>
16)‘_vsnprintf’在此作用域中尚未声明
#include <stdarg.h>
将_vsnprintf改成vsnprintf
17)‘_snprintf’在此作用域中尚未声明
#include <stdarg.h>
将_snprintf改成snprintf
18)‘_access’在此作用域中尚未声明
#include <unistd.h>
将_access改成access
19)
typedef ACE_Hash_Map_Manager< CQQ_USERSERIAL, SUserAppDACItem*,ACE_Thread_Mutex> MAP_USER_APP_DAC;
ACE_Thread_Mutex在windows中和ACE_SYNCH_RECURSIVE_MUTEX效果相同,都为递归锁。
但在linux下
ACE_Thread_Mutex为非递归锁,同一个线程第二次进入则会死锁
20)
char p;
windwos下为:
typeid(p).name() 等于 "char"
linux下为:
typeid(p).name() 等于 "c"
unsigned long p
windwos下为:
typeid(p).name() 等于 "unsigned long"
linux下为:
typeid(p).name() 等于 "m"
unsigned short p
windwos下为:
typeid(p).name() 等于 "unsigned short"
linux下为:
typeid(p).name() 等于 "t"
题目传送门: http://www.acmore.net/JudgeOnline/contest.php?cid=1027
A::难度值4
考点:指针的运用
CodeForce 251A 官方题解:
Let's select the rightmost point of ourtriplet. In order to do this we can iterate over all points in ascending orderof their X-coordinate. At the same time we'll maintain a pointer to theleftmost point which lays on the distance not greater than d from the currentrightmost point. We can easily find out the number of points in the segmentbetween two pointers, excluding the rightmost point. Let's call this number k.Then there exist exactly k * (k - 1) / 2 triplets of points with the fixedrightmost point. The only thing left is to sum up these values for allrightmost points.
思路: 从右向左遍历数组,设置两个指针I,j分别控制3点中的首尾两点,只要a[j]-a[i]<=d ,则在固定尾指针的情况下,从首指针之后的数中任意挑选两个都能成为3 points,那就是用C(x,2)组合数就能解决,由于只有两个指针的遍历移动,所以复杂度为O(2*n)
注意:涉及到组合数, k * (k - 1) / 2会超出int范围,所以要使用long long (VC下是__int64)
B:难度值0
考点:字符串比较函数
先比较两个字符串的长度,长度相同时strcmp两个字符串就行,不过要注意审题数的范围是10^100所以不能用int或long long,不要盲目提交。
C:难度值 1
考点:递归
每一个蜂窝步数 = 左边邻近两个蜂窝步数之和
因此递归解决,周练原题
D:难度值2
考点:字符串应用
数据很弱,用暴力就能够做出
比如abbab,我们插入无关字符构造成新的字符串 #a#b#b#a#b#b#
这样做的好处是不用判断它是轴对称还是中心对称
对于每一个字符向两边拓展遍历,找出他的最大回文数后,遍历一遍取最大值即可
不用manacher算法就可以解,如果这题数据是100000以上那么就必须用manacher来做了
以下是manacher的一个解析,大家可以学习一下这个做法
http://blog.sina.com.cn/s/blog_70811e1a01014esn.html
E:难度2
考点:sort排序
结构体排序。
姓名查找如果用哈希表更快,但这题数据不强,直接依次匹配即可。
F:难度3
考点:模拟
直接按他的规则模拟走法,走过的点标记为已经访问过,如果走到访问过的点,就说明成环了。
G:难度3
考点:位运算
分别取异或,最后剩下的数就是要求的数
a,b 看为二进制数 比如 1和15的二进制分别是:
0001
^ 1111
________
1110
这时候假设再来一个15 取异或
1110
^ 1111
________
0001
我们又得到了1,这时候我们发现,出现偶数次的数字被自己抵消了,即a^a=0
我们运用这个结论可以很快得出答案,复杂度O(n)
H:难度2
考点:点与直线
判断最多有多少点在同一直线上
任意两点确定直线后每个点依次带入直线方程。求出最大值即可。
I:难度2
考点:数据结构——栈
题意明确是栈的思想,这题明显用数组模拟栈更方便
back就把当前指针向前指,forward就把当前指针向后指
visit就把尾指针+1。
注意有首页和尾页,指针要注意处理不然容易越界
J:难度1
考点:简单循环
直接循环找每个窗户第一个”….”所在的行数就行