2021 机试


#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;	 
	  
	  
	  
	  }






		
  
  
  
  
  






















  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值