A. C璇瑷瀹氭椂鍣
杩欎釜绋嫔簭鐢ㄥ氱嚎绋嬫瘆杈冨ソ瑙e喅.
#include <windows.h>
#include <iostream>
#include <conio.h>
using namespace std;
const int MAX_SECOND = 1000 * 60;
DWORD WINAPI MyThread(PVOID pParam)
{
int nSum = 0;
DWORD dwFirstTime = GetTickCount();
cout<<"锅氶桦紑濮,璇峰湪"<<MAX_SECOND / 1000 <<"绉掑唴锲炵瓟."<<endl;
do
{
cout<<"1 + 2 = ? 璇峰洖绛:"<<endl;
nSum = getch();
cout<<char(nSum)<<endl;
if(nSum == 3 + '0')
{
cout<<"绛旀堟g‘"<<endl;
return 0;
}
}while(GetTickCount() - dwFirstTime <= MAX_SECOND);
return 0;
}
int main()
{
HANDLE hThread = CreateThread(NULL, 0, MyThread, 0, NULL, NULL);
WaitForSingleObject(hThread, MAX_SECOND);
CloseHandle(hThread);
return 0;
}
B. 濡备綍鍒朵綔鐢垫簮瀹氭椂鍣
銆銆1銆佺数婧愬畾镞跺櫒鍖呮嫭澹充綋銆佺数婧愯緭鍏ユ彃鑴氥佺数婧愯緭鍑烘彃搴у瓟銆佹椂闂磋剧疆寮鍏冲拰澹充綋鍐呯殑镞堕棿鎺у埗鐢佃矾锛屽叾涓镞堕棿鎺у埗鐢佃矾鍖呮嫭鏁存祦绋冲帇婧愩佽℃椂鍗曞厓鍜岀数婧愯緭鍑烘带鍒跺崟鍏冿纴璁℃椂鍗曞厓鐢辨椂闂磋惧畾鍗曞厓鍜屽垎棰戣℃暟鍗曞厓缁勬垚锛屽苟涓擜銆佹椂闂磋惧畾鍗曞厓鐢卞甫镞堕棿璁剧疆寮鍏崇殑鐢甸樆鍣ㄧ粍浠跺拰鐢靛瑰櫒缁勬垚RC鎸钻$数璺锛
銆銆2銆佷负浜呜兘澶熺簿纭鍦拌剧疆镞堕棿锛屽苟閲囩敤链灏戞暟閲忕殑鐢甸樆鍣锛屾墍璁捐$殑镞堕棿璁剧疆寮鍏冲彲浠ョ敱涓鍙鎴栧氩彧𨰾ㄦ。寮鍏崇粍鎴愶纴钖屾椂灏哛C鎸钻″櫒鍐呯殑鐢甸樆鍣ㄧ粍浠跺垎鎴愪竴缁勬垨澶氱粍锛屽苟涓斿垎鍒涓庢嫧妗e紑鍏崇浉杩炴帴锛屼娇𨰾ㄦ。寮鍏崇殑姣忎竴妗d綅缃镄勭‘瀹氶兘鑳藉瑰簲鎶曞叆RC鎸钻″櫒
C. 鍝佺泭瀹氭椂鍣ㄦ庝箞璁剧疆
宸ュ叿锛氩搧鐩婂畾镞跺櫒
1銆佸厛瑙傚疗闱㈡澘镞堕挓鏄钖︿负褰揿墠镞堕棿锛屽傞渶瑕佹牎姝o纴鎸変笅钬沧椂阍颎濇寜阍涓嶈佹斁寮锛屾帴镌鎸夆沧槦链颎濄佲滃皬镞垛濄佲滃垎阍颎濅笁涓鎸夐挳杩涜岃皟鑺傚嵆鍙銆