快速出一道A+B

样例可以由以下代码跑出来:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
    FILE *fpin = NULL , *fpout = NULL;
    char str[101] = "";
    char namein[64] = "";
    char nameout[64] = "";
    int Total=5,current=-1;
    
   void finin();
  void foutout(); 
 
void finout(){
    for(int i=0;i<20;i++){
if(i%4==0) current++; 
sprintf(namein , "f:\oj\1\%d.in",i);  
sprintf(nameout , "f:\oj\1\%d.out",i); 
//主要功能是把格式化的数据写入某个字符串中,即发送格式化输出到 string 所指向的字符串。存在了buffer溢出的可能性
printf("%s创建成功 %s创建成功 " , namein , nameout);
fpin = fopen(namein , "w");
fpout = fopen(nameout , "w");
if( fpin == NULL ) break ;
    //判断文件是否打开失败
// fprintf(fpin,"%d",current);
finin();
foutout();
fclose(fpin);
fclose(fpout);
}
}
 
    int a[100],b[100],num[5];
    
void finin(){ //对单个输入文件处理 
    for (int j=0;j<20;j++){
    a[ j ] = rand()%num[current];
    b[ j ] = rand()%num[current];
    fprintf(fpin,"%d %d ", a[ j ] , b[ j ] );
    } 
}
 
void foutout(){
    for (int j=0;j<20;j++){
    fprintf(fpout,"%d ", a[ j ] + b[ j ] );
    } 
}
 
int main() {
    srand(time(NULL)); //初始化随机数种子 
    int n=10;
     for(int i=0;i<5;i++){
         num[i]=n;
         n=n<<3;
     } //数据分布 
   finout();
}



欢迎来我们oj刷题 oj地址:http://www.npumdacm.top/
原文地址:https://www.cnblogs.com/tlysMoodspace/p/11813676.html