Another test

寻找重复数值的算法实现
Problem 1001 Duplicate Pair

Accept: 5142    Submit: 24343
Time Limit: 1000 mSec    Memory Limit : 65536 KB

Problem Description

An array of length n, with address from 1 to n inclusive, contains entries from the set {1,2,...,n-1} and there's exactly two elements with the same value. Your task is to find out the value.

Input

Input contains several cases.
Each case includes a number n (1<n<=10^6), which is followed by n integers.
The input is ended up with the end of file.

Output

Your must output the value for each case, one per line.

Sample Input

2 1 1 4 1 2 3 2

Sample Output

1 2

Source

IBM Challenge 2004.1 
 1 #include <cstdio>
 2 #include <cstring>
 3 int a[1000005];
 4 int main()
 5 {
 6     int n;
 7     while(scanf("%d",&n) != EOF)
 8     {
 9 
10         memset(a,0,sizeof a);
11         int ans = 0;
12         for(int i = 0 ; i < n ; i++)
13         {
14             int temp;
15             scanf("%d",&temp);
16             a[temp]++;
17             if(a[temp] == 2) ans = temp;
18         }
19         printf("%d\n",ans);
20     }
21     return 0;
22 }
View Code

 

转载于:https://www.cnblogs.com/hyq123456/p/5402970.html

#include <windows.h> #include <iostream> // 全局变量 DWORD g_BreakpointAddr = 0; // Hook目标地址 PVOID g_VehHandler = nullptr; // VEH句柄 // VEH异常处理函数 LONG WINAPI MyExceptionHandler(PEXCEPTION_POINTERS ExceptionInfo) { if (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_SINGLE_STEP) { if ((DWORD)ExceptionInfo->ExceptionRecord->ExceptionAddress == g_BreakpointAddr) { std::cout << ">>> MessageBoxA Hooked! <<<\n"; // 获取参数 const char* text = (const char*)ExceptionInfo->ContextRecord->Ecx; const char* caption = (const char*)ExceptionInfo->ContextRecord->Edx; std::cout << "Text: " << (text ? text : "NULL") << "\n"; std::cout << "Caption: " << (caption ? caption : "NULL") << "\n"; // 修改参数(演示如何篡改) if (text && strcmp(text, "aaa") == 0) { ExceptionInfo->ContextRecord->Ecx = (DWORD)"HACKED!"; } // 跳过原始调用(设置返回值) ExceptionInfo->ContextRecord->Eax = IDOK; // 继续执行(跳过2字节的call指令) ExceptionInfo->ContextRecord->Eip += 2; return EXCEPTION_CONTINUE_EXECUTION; } } return EXCEPTION_CONTINUE_SEARCH; } int main() { // 1. 获取MessageBoxA地址 HMODULE hUser32 = LoadLibraryA("user32.dll"); if (!hUser32) { std::cerr << "Failed to load user32.dll\n"; return 1; } g_BreakpointAddr = (DWORD)GetProcAddress(hUser32, "MessageBoxA"); if (!g_BreakpointAddr) { std::cerr << "Failed to find MessageBoxA\n"; return 1; } std::cout << "MessageBoxA address: 0x" << std::hex << g_BreakpointAddr << "\n"; // 2. 设置硬件断点 CONTEXT ctx = { 0 }; ctx.ContextFlags = CONTEXT_DEBUG_REGISTERS; ctx.Dr0 = g_BreakpointAddr; // 断点地址 ctx.Dr7 = 0x00000001; // DR0启用执行断点 if (!SetThreadContext(GetCurrentThread(), &ctx)) { std::cerr << "SetThreadContext failed: " << GetLastError() << "\n"; return 1; } // 3. 注册VEH异常处理 g_VehHandler = AddVectoredExceptionHandler(1, MyExceptionHandler); if (!g_VehHandler) { std::cerr << "AddVectoredExceptionHandler failed\n"; return 1; } std::cout << "VEH handler registered. Testing hook...\n\n"; // 4. 测试Hook MessageBoxA(NULL, "aaa", "Original Caption", MB_OK); MessageBoxA(NULL, "bbb", "Another Test", MB_OK); // 5. 清理 RemoveVectoredExceptionHandler(g_VehHandler); std::cout << "\nHook unregistered. Program exiting.\n"; return 0; } 把这个代码修改成win10 x64版本的
07-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值