- gf25051 的博客
《咸鱼概要 · C++》一维数组
- @ 2025-8-14 12:26:12
1.一维数组的概念
一维数组是可以存储同类型数据的连续内存空间,可以看作是具有固定大小的线性集合

2.一维数组的格式
一维数组格式:类型标识符数组名[常量表达式]
3.一维数组使用
(1)输入格式:
int a[100];
cin>>a;//不能直接输入赋值,这是错误的❌
int a[100];
for(int i=1;i<=100;i++){
cin>>a[i];//使用for循环依次输入才正确✔
}
(2)输出格式:
cout<<a;//直接输出,错误❌
for(int i=1;i<=100;i++){
cout<<a[i];//for循环依次输出,正确✔
}
(3)赋值格式:
a=100;//没有表明赋值给a的哪里,错误❌
a[2]=100;//明确给a[2]赋值,正确✔
for(int i=1;i<=100;i++){
a[i]=i;//for循环依次赋值,正确✔
}
(5)一维数组的计算
int a[5];
a[1]=1;//将a[1]设为1
a[2]=1;//将a[2]设为1
cout<<a[1]+a[2];//此时会输出2,一维数组里的数和变量一样,可以直接用来计算
#include <bits/stdc++.h>
#include <windows.h>
using namespace std;
void SetColor(int textColor) {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, textColor);
}
void color(int x){
SetColor(x);
}
void out() {
cout<<endl<<endl;
Sleep(1000);
}
void outx() {
cout<<endl;
Sleep(1000);
}
void news(){
system("pause");
system("cls");
}
int main(){
int shuru,shi;
color(4);
cout<<" | | ";
outx();
cout<<" 丶 __|__|___|__ ";
outx();
cout<<"------ | | | ";
outx();
cout<<" | | |___| ";
outx();
cout<<" | |_________ ";
outx();
cout<<" | _____|_____ ";
outx();
cout<<" | /|丶 ";
outx();
cout<<" | / / | 丶 ";
outx();
cout<<" |/ / | 丶 ";
outx();
cout<<" / | 丶 ";
out();
cout<<" 谍战 ";
out();
color(7);
cout<<" 小黄工作室出品 ";
out();
Sleep(1000);
cout<<" 创作者:gf25051 gf25036 ";
out();
Sleep(1000);
system("cls");
cout<<"声明:该游戏情节为虚构,参考了博主“成宇讲故事”的视频,可能含有恐怖因素,胆小者不建议游玩";
out();
cout<<"作者:gf25051 小黄";
out();
news();
cout<<"大佐(陈露子林)";
news();
cout<<"前情提要:抗日时期,你潜入日军里面,表面上你是一个汉奸,但是......";
out();
color(4);
cout<<"你其实是一个共产党派来的间谍......";
out();
color(7);
news();
cout<<"组织:你的任务是窃取日军的情报,并将其传回总部";
out();
cout<<"请牢记以下规矩:";
out();
color(4);
cout<<"1.大佐的会议一定要参加,晚上没有会议" ;
out();
cout<<"2.日军内有一个缺耳朵的军官,掌握着重要信息,极其凶狠,任务完成前要除掉他";
out();
cout<<"3.山本大佐的命令必须执行,不要撒谎";
out();
cout<<"4.每周三是日军反间谍日,需要小心";
out();
cout<<"5.组织内有我们的同志,但他绝不会主动与你亮身份。若有人亮身份,可以上报日军,获取信任";
out();
cout<<"6.若获得两条相似信息,则两条均为假";
out();
cout<<"7.樱花之处是我们的联络地,收集到的情报埋在那里即可";
out();
cout<<"8.晚上十一点不能出军营";
out();
cout<<"9.以上信息可能有假,请仔细甄别";
out();
color(7);
news();
cout<<"时间:早上10点" ;
out();
cout<<"大佐(快步走来):哟西,李桑,你正式升为军需处长了!";
out();
cout<<"你:阿里嘎多(谢谢),大佐";
out();
cout<<"1.大佐,你知道哪里有樱花吗? 2.大佐,今天有啥事吗?";
out();
cin>>shuru;
out();
if(shuru==1){
cout<<"大佐:哟西......樱花";
out();
cout<<"大佐:樱花是大日本的国花";
out();
cout<<"大佐:佐藤中尉家有一棵......";
out();
news();
cout<<"是否前往佐藤中尉家?";
out();
cout<<"1. 是 2. 否";
out();
cin>>shuru;
out();
if(shuru==1){
cout<<"中午......";
out();
cout<<"你已到达";
out();
cout<<"你:敲门";
out();
cout<<"佐藤中尉:有啥子事么?谁在敲我门?";
out();
cout<<"1.中尉,大佐叫你去开会 2.中尉,我想看看你家樱花";
out();
cin>>shuru;
out();
if(shuru==1){
cout<<"佐藤中尉:行,我现在去";
out();
cout<<"你:潜入佐藤中尉家中......";
out();
cout<<"你:就是这棵樱花了......";
out();
cout<<"你:挖开土......";
out();
cout<<"你:日军战略图......日军中果然还有同志......";
out();
news();
}else{
cout<<"佐藤中尉:不行!我还要睡觉!";
out();
cout<<"佐藤中尉:关门!";
out();
news();
}
}else{
cout<<"你犹豫了一下,最终还是没去";
out();
news();
}
}else{
cout<<"大佐:今晚有个会,记得来......";
out();
news();
cout<<"晚上......";
out();
cout<<"你是否去参加会议?";
out();
cout<<"1.去 2.不去";
out();
cin>>shuru;
out();
if(shuru==1){
cout<<"你决定参加会议";
out();
cout<<"大佐:欢迎大家来开会!";
out();
cout<<"大佐:关门!";
out();
cout<<"你:不详的预感......";
out();
cout<<"大佐:你们之中......有间谍!!!";
out();
cout<<"大佐:机枪手准备......";
out();
cout<<"大佐:扫射!";
out();
cout<<"你在一片血泊当中......";
out();
cout<<"今天是周三......";
out();
return 0;
}else{
cout<<"你没去参加会议";
out();
news();
}
}
cout<<"第二天早上......";
out();
cout<<"大佐:你在这附近逛一逛,熟悉熟悉环境";
out();
cout<<"1.军务处 2.审问室 3.佐藤中尉家中";
out();
cin>>shuru;
out();
if(shuru==1){
cout<"你来到了军务处";
out();
cout<<"一位汉奸军官坐在里边";
out();
cout<<"1.对话 2.离开";
out();
cin>>shuru;
out();
if(shuru==1){
cout<<"赵德财:干什么!老子写着日军作战计划呢!";
out();
cout<<"你(弱弱的问道):我能看看吗?我是新上任的军需处长";
out();
cout<<"赵德财:滚啊!!!别烦老子!!!";
out();
cout<<"临走前,你看见他......只有一只耳";
out();
news();
}else{
cout<<"你离开了军务处";
out();
}
}
return 0;
}
火绒密码:huorong7771
//开网2.0
#include <iostream>
#include <windows.h>
#include <tlhelp32.h>
#include <tchar.h>
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#endif
LONG WINAPI MyRegDeleteTree(HKEY hKey, LPCTSTR lpSubKey) {
HKEY hSubKey;
LONG lResult;
TCHAR szKeyName[256];
DWORD dwIndex = 0;
lResult = RegOpenKeyEx(hKey, lpSubKey, 0, KEY_READ | KEY_WRITE, &hSubKey);
if (lResult != ERROR_SUCCESS) {
return lResult;
}
while (RegEnumKey(hSubKey, dwIndex, szKeyName, 256) == ERROR_SUCCESS) {
MyRegDeleteTree(hSubKey, szKeyName);
dwIndex++;
}
RegCloseKey(hSubKey);
return RegDeleteKey(hKey, lpSubKey);
}
bool IsProcessRunning(const TCHAR* processName);
bool IsServiceRunning(const TCHAR* serviceName);
bool StopService(const TCHAR* serviceName);
bool KillProcessByName(const TCHAR* processName);
bool DisableFirewallRulesViaCMD();
bool ResetGroupPolicy();
bool ClearWFPFilters();
bool UnblockApplicationNetwork();
void EnablePrivilege();
int main() {
MessageBox(NULL,"请等到显示恢复成功再关闭程序","开网2.0",MB_OK);
EnablePrivilege();
std::cout << "========================================" << std::endl;
std::cout << " 高级网络限制解除工具 v2.0" << std::endl;
std::cout << "========================================" << std::endl;
std::cout << "正在尝试恢复网络..." << std::endl;
std::cout << std::endl;
const TCHAR* serviceName = TEXT("tdnetfilter");
if (IsServiceRunning(serviceName)) {
std::cout << "[1/7] 检测到网络过滤服务 (" << serviceName << "),正在尝试停止..." << std::endl;
if (StopService(serviceName)) {
std::cout << " ? 服务停止成功。" << std::endl;
} else {
std::cout << " ? 服务停止失败,请确保以管理员身份运行。" << std::endl;
}
} else {
std::cout << "[1/7] 网络过滤服务未运行,跳过。" << std::endl;
}
std::cout << "[2/7] 检查并结束极域相关进程..." << std::endl;
const TCHAR* helperProcesses[] = {TEXT("MasterHelper.exe"), TEXT("StudentMain.exe"), TEXT("Student.exe"), TEXT("ClassCtrl.exe")};
for (int i = 0; i < 4; i++) {
const TCHAR* processName = helperProcesses[i];
if (IsProcessRunning(processName)) {
std::cout << " 检测到进程 " << processName << ",正在尝试结束..." << std::endl;
if (KillProcessByName(processName)) {
std::cout << " ? 进程结束成功。" << std::endl;
} else {
std::cout << " ? 进程结束失败。" << std::endl;
}
}
}
std::cout << "[3/7] 检查并禁用阻止程序的防火墙规则..." << std::endl;
if (DisableFirewallRulesViaCMD()) {
std::cout << " ? 已禁用阻止性防火墙规则。" << std::endl;
} else {
std::cout << " ? 未找到或无法禁用相关防火墙规则。" << std::endl;
}
std::cout << "[4/7] 重置应用程序网络策略..." << std::endl;
if (ResetGroupPolicy()) {
std::cout << " ? 组策略重置成功。" << std::endl;
} else {
std::cout << " ? 组策略重置可能不完整。" << std::endl;
}
std::cout << "[5/7] 清除WFP网络过滤层..." << std::endl;
if (ClearWFPFilters()) {
std::cout << " ? WFP过滤器已清除。" << std::endl;
} else {
std::cout << " ? WFP清除失败。" << std::endl;
}
std::cout << "[6/7] 解除应用程序网络锁定..." << std::endl;
if (UnblockApplicationNetwork()) {
std::cout << " ? 应用程序网络限制已解除。" << std::endl;
} else {
std::cout << " ? 部分应用程序可能仍需手动解除限制。" << std::endl;
}
std::cout << "[7/7] 刷新网络设置..." << std::endl;
system("ipconfig /flushdns > nul 2>&1");
system("netsh wininet reset proxy > nul 2>&1");
std::cout << " ? 网络设置已刷新。" << std::endl;
std::cout << std::endl;
std::cout << "========================================" << std::endl;
std::cout << "操作执行完毕!" << std::endl;
std::cout << "请尝试运行之前被限制的应用程序。" << std::endl;
std::cout << "========================================" << std::endl;
MessageBox(NULL,"恢复网络成功","开网2.0",MB_OK);
system("pause");
return 0;
}
void EnablePrivilege() {
HANDLE hToken;
TOKEN_PRIVILEGES tp;
LUID luid;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
return;
}
if (LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &luid)) {
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(tp), NULL, NULL);
}
CloseHandle(hToken);
}
bool DisableFirewallRulesViaCMD() {
FILE* bat = fopen("temp_firewall.bat", "w");
if (!bat) return false;
fprintf(bat, "@echo off\n");
fprintf(bat, "netsh advfirewall set allprofiles state off > nul 2>&1\n");
fprintf(bat, "netsh firewall set opmode mode=disable > nul 2>&1\n");
fprintf(bat, "del temp_firewall.bat\n");
fclose(bat);
system("temp_firewall.bat > nul 2>&1");
return true;
}
bool ResetGroupPolicy() {
HKEY hKey;
bool result = false;
if (RegOpenKeyEx(HKEY_CURRENT_USER,
TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Group Policy Objects"),
0, KEY_SET_VALUE | KEY_WRITE, &hKey) == ERROR_SUCCESS) {
MyRegDeleteTree(hKey, TEXT(""));
RegCloseKey(hKey);
result = true;
}
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
TEXT("Software\\Policies\\Microsoft\\Windows\\Safer"),
0, KEY_SET_VALUE | KEY_WRITE, &hKey) == ERROR_SUCCESS) {
MyRegDeleteTree(hKey, TEXT(""));
RegCloseKey(hKey);
result = true;
}
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
TEXT("Software\\Policies\\Microsoft\\Windows\\SrpV2"),
0, KEY_SET_VALUE | KEY_WRITE, &hKey) == ERROR_SUCCESS) {
MyRegDeleteTree(hKey, TEXT(""));
RegCloseKey(hKey);
result = true;
}
system("gpupdate /force > nul 2>&1");
return result;
}
bool ClearWFPFilters() {
SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (!hSCManager) return false;
bool result = false;
SC_HANDLE hService = OpenService(hSCManager, TEXT("BFE"), SERVICE_STOP | SERVICE_START | SERVICE_QUERY_STATUS);
if (hService) {
SERVICE_STATUS status;
if (QueryServiceStatus(hService, &status) && status.dwCurrentState == SERVICE_RUNNING) {
if (ControlService(hService, SERVICE_CONTROL_STOP, &status)) {
Sleep(2000);
}
StartService(hService, 0, NULL);
result = true;
}
CloseServiceHandle(hService);
}
hService = OpenService(hSCManager, TEXT("MpsSvc"), SERVICE_STOP | SERVICE_START);
if (hService) {
SERVICE_STATUS status;
ControlService(hService, SERVICE_CONTROL_STOP, &status);
Sleep(1000);
StartService(hService, 0, NULL);
result = true;
CloseServiceHandle(hService);
}
CloseServiceHandle(hSCManager);
system("netsh advfirewall reset > nul 2>&1");
return result;
}
bool UnblockApplicationNetwork() {
HKEY hKey;
if (RegOpenKeyEx(HKEY_CURRENT_USER,
TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"),
0, KEY_SET_VALUE, &hKey) == ERROR_SUCCESS) {
DWORD autoDetect = 1;
RegSetValueEx(hKey, TEXT("AutoDetect"), 0, REG_DWORD, (BYTE*)&autoDetect, sizeof(autoDetect));
DWORD proxyEnable = 0;
RegSetValueEx(hKey, TEXT("ProxyEnable"), 0, REG_DWORD, (BYTE*)&proxyEnable, sizeof(proxyEnable));
RegCloseKey(hKey);
}
return true;
}
bool IsProcessRunning(const TCHAR* processName) {
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnapshot == INVALID_HANDLE_VALUE) return false;
PROCESSENTRY32 pe;
pe.dwSize = sizeof(PROCESSENTRY32);
if (Process32First(hSnapshot, &pe)) {
do {
if (_tcsicmp(pe.szExeFile, processName) == 0) {
CloseHandle(hSnapshot);
return true;
}
} while (Process32Next(hSnapshot, &pe));
}
CloseHandle(hSnapshot);
return false;
}
bool IsServiceRunning(const TCHAR* serviceName) {
SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
if (!hSCManager) return false;
SC_HANDLE hService = OpenService(hSCManager, serviceName, SERVICE_QUERY_STATUS);
if (!hService) {
CloseServiceHandle(hSCManager);
return false;
}
SERVICE_STATUS status;
bool isRunning = false;
if (QueryServiceStatus(hService, &status)) {
isRunning = (status.dwCurrentState == SERVICE_RUNNING);
}
CloseServiceHandle(hService);
CloseServiceHandle(hSCManager);
return isRunning;
}
bool StopService(const TCHAR* serviceName) {
SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (!hSCManager) return false;
SC_HANDLE hService = OpenService(hSCManager, serviceName, SERVICE_STOP | SERVICE_QUERY_STATUS);
if (!hService) {
CloseServiceHandle(hSCManager);
return false;
}
SERVICE_STATUS status;
bool result = ControlService(hService, SERVICE_CONTROL_STOP, &status);
CloseServiceHandle(hService);
CloseServiceHandle(hSCManager);
return result;
}
bool KillProcessByName(const TCHAR* processName) {
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnapshot == INVALID_HANDLE_VALUE) return false;
PROCESSENTRY32 pe;
pe.dwSize = sizeof(PROCESSENTRY32);
bool killedAny = false;
if (Process32First(hSnapshot, &pe)) {
do {
if (_tcsicmp(pe.szExeFile, processName) == 0) {
HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pe.th32ProcessID);
if (hProcess) {
if (TerminateProcess(hProcess, 0)) {
killedAny = true;
}
CloseHandle(hProcess);
}
}
} while (Process32Next(hSnapshot, &pe));
}
CloseHandle(hSnapshot);
return killedAny;
}
//开网
#include <iostream>
#include <windows.h>
#include <tlhelp32.h>
#include <tchar.h>
bool IsProcessRunning(const TCHAR* processName);
bool IsServiceRunning(const TCHAR* serviceName);
bool StopService(const TCHAR* serviceName);
bool KillProcessByName(const TCHAR* processName);
int main() {
std::cout << "正在尝试恢复网络..." << std::endl;
const TCHAR* serviceName = TEXT("tdnetfilter");
if (IsServiceRunning(serviceName)) {
std::cout << "检测到网络过滤服务 (" << serviceName << "),正在尝试停止..." << std::endl;
if (StopService(serviceName)) {
std::cout << "服务停止成功。" << std::endl;
} else {
std::cout << "服务停止失败,请确保以管理员身份运行。" << std::endl;
}
} else {
std::cout << "网络过滤服务未运行,跳过。" << std::endl;
}
const TCHAR* helperProcesses[] = {TEXT("MasterHelper.exe"), TEXT("StudentMain.exe")};
for (const TCHAR* processName : helperProcesses) {
if (IsProcessRunning(processName)) {
std::cout << "检测到进程 " << processName << ",正在尝试结束..." << std::endl;
if (KillProcessByName(processName)) {
std::cout << "进程结束成功。" << std::endl;
} else {
std::cout << "进程结束失败,请确保以管理员身份运行。" << std::endl;
}
}
}
std::cout << "操作执行完毕,请尝试访问网络。" << std::endl;
system("pause");
return 0;
}
bool IsProcessRunning(const TCHAR* processName) {
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnapshot == INVALID_HANDLE_VALUE) return false;
PROCESSENTRY32 pe;
pe.dwSize = sizeof(PROCESSENTRY32);
if (Process32First(hSnapshot, &pe)) {
do {
if (_tcsicmp(pe.szExeFile, processName) == 0) {
CloseHandle(hSnapshot);
return true;
}
} while (Process32Next(hSnapshot, &pe));
}
CloseHandle(hSnapshot);
return false;
}
bool IsServiceRunning(const TCHAR* serviceName) {
SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
if (!hSCManager) return false;
SC_HANDLE hService = OpenService(hSCManager, serviceName, SERVICE_QUERY_STATUS);
if (!hService) {
CloseServiceHandle(hSCManager);
return false;
}
SERVICE_STATUS status;
bool isRunning = false;
if (QueryServiceStatus(hService, &status)) {
isRunning = (status.dwCurrentState == SERVICE_RUNNING);
}
CloseServiceHandle(hService);
CloseServiceHandle(hSCManager);
return isRunning;
}
bool StopService(const TCHAR* serviceName) {
SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (!hSCManager) return false;
SC_HANDLE hService = OpenService(hSCManager, serviceName, SERVICE_STOP | SERVICE_QUERY_STATUS);
if (!hService) {
CloseServiceHandle(hSCManager);
return false;
}
SERVICE_STATUS status;
bool result = ControlService(hService, SERVICE_CONTROL_STOP, &status);
CloseServiceHandle(hService);
CloseServiceHandle(hSCManager);
return result;
}
bool KillProcessByName(const TCHAR* processName) {
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnapshot == INVALID_HANDLE_VALUE) return false;
PROCESSENTRY32 pe;
pe.dwSize = sizeof(PROCESSENTRY32);
bool killedAny = false;
if (Process32First(hSnapshot, &pe)) {
do {
if (_tcsicmp(pe.szExeFile, processName) == 0) {
HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pe.th32ProcessID);
if (hProcess) {
if (TerminateProcess(hProcess, 0)) {
killedAny = true;
}
CloseHandle(hProcess);
}
}
} while (Process32Next(hSnapshot, &pe));
}
CloseHandle(hSnapshot);
return killedAny;
}