#include<iostream>
#include<stdio.h>
#include<windows.h>
#include<string.h>
#include<fstream>
using namespace std;
int main()
{
std::ofstream ofs;
std::ifstream ifs;
ofs.open("E://04.txt",std::ios::out|std::ios::trunc);
ofs<<1<<2<<3<<5;
ofs.close();
ifs.open("E://04.txt");
char ch[256]={0};
ifs>>ch;
printf("%s\n",ch);
int k=0;
int length=0;
while(ch[k]>'0'&&ch[k]<'20')
{
length++;
k++;
}
cout<<"长度"<<length<<endl;
// cout<<"输出拿到的数据呀:"<<endl;
// cout<<ch[0]<<ch[1]<<ch[2]<<endl;
int a[3]={};
for(int p=0;p<length;p++)
{
a[p]=ch[p]-48;
}
//cout<<a[0]<<a[1]<<a[2]<<endl; //输入到数组中啦
ifs.close();
//把数组划分成相等的两部分
int h1=0,h2=0;
for(int m=0;m<=length-2;m++)//0 - m m+1 - lenght-1
{
h1=0;h2=0;
for(int s=0;s<=m;s++){//前半部分
h1+=(a[s]);
}
for(int d=m+1;d<=length-1;d++){//后半部分
h2+=(a[d]);
}
if(h1==h2)
{
cout<<"成功"<<endl;
ofs.open("E://output.txt",std::ios::out|std::ios::trunc);
ofs<<"YES";
ofs.close();
Sleep(80000);
return 0;
}
}
cout<<"失败"<<endl;
ofs.open("E://output.txt",std::ios::out|std::ios::trunc);
ofs<<"NO";
ofs.close();
Sleep(80000);
return 0;
}
2021 机试
最新推荐文章于 2024-09-11 09:33:21 发布