⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 求频度矩阵a.txt

📁 一些解决线形方程组的并行计算的程序,希望对大家有一点帮助
💻 TXT
字号:
// new.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <direct.h>
using namespace std;

int main()
{
    FILE *fp=NULL;
    FILE *fp1=NULL;
	char str1[60],str2[10],str3[10],str4[10],str5[10],str6[10];
    long buf1[2],buf2[44050*2];
	long offset=0,index;
	int  n=0,m=0,count=0,ndir=0,num_index=0;
	int nPos1,nPos2,len;
    float f1;
	string strindex;
    vector<int> vector1;
	memset(str1,0,60);
	memset(str2,0,10);
	memset(str3,0,10);
	memset(str4,0,10);
	memset(str4,0,10);
	memset(str5,0,10);
    memset(str6,0,10);
	memset(buf2,0,44050*2);
	buf1[0]=44050,buf1[1]=44050;
	if((fp1=fopen("c:\\010","wb"))==NULL)
     {
       printf("%s","Can not open the file");
       exit(1);
     }
	fwrite(buf1,4,2,fp1);
    fwrite(buf2,4,44050*2,fp1);
    if((fp=fopen("c:\\dic","rb"))==NULL)
     {
       printf("%s","Cannot open the file.\n");
       exit(1);
     }
	while(!feof(fp))
          {   
	        fgets(str1,60,fp);
            nPos1=strcspn(str1,":");
            strncpy(str2,str1,nPos1);
            nPos2=strcspn(str1+nPos1+1,":");
            strncpy(str3,str1+nPos1+1,nPos2);
			strindex+=str3;//
			m=strlen(str3);
            strncpy(str4,str1+nPos1+nPos2+2,strlen(str1)-(nPos1+nPos2+2));
    	    vector1.push_back(atoi(str4));
	        n+=atoi(str4);
            while(fgets(str1,60,fp))
			{           
             nPos1=strcspn(str1,":");
             strncpy(str5,str1,nPos1);
             if(!strcmp(str2,str5))
			  { 
                 nPos2=strcspn(str1+nPos1+1,":");
                 strncpy(str3,str1+nPos1+1,nPos2);
				 strindex+=str3;//
                 strncpy(str4,str1+nPos1+nPos2+2,strlen(str1)-(nPos1+nPos2+2));
		         vector1.push_back(atoi(str4));
                 n=n+atoi(str4);
			 }  
	         else
			 {   
				 count++;
				 if(count!=1)
				 {
					 offset+=num_index*8;
				 }
				 buf1[0]=offset;
				 buf1[1]=vector1.size();
				 fseek(fp1,8+(count-1)*8,0);
				 int n1=ftell(fp1);
				 fwrite(buf1,4,2,fp1);
				 fseek(fp1,8+8*44050+offset,0);
			   	 int j;
	             for(j=0;j<vector1.size();j++)
				 {    
                     f1=float(vector1.at(j))/n;			
                     strindex.copy(str3,m,m*j);
                     index=atoi(str3);
                     fwrite(&index,4,1,fp1);
					 fwrite(&f1,4,1,fp1);
					 memset(str6,0,10);	        
				 }
		  strindex.erase();
		  printf("\n");
		  num_index=vector1.size();
          vector1.clear();
		  n=0;
          fseek(fp,-strlen(str1),1);//
		  break;
		 }   
	   }
         if(vector1.size()!=0)             
		 {   
		   count++;
		   if(count!=1)
		   {
			 offset+=num_index*8;
		   }
		   buf1[0]=offset;
		   buf1[1]=vector1.size();
		   fseek(fp1,8+(count-1)*8,0);
		   fwrite(buf1,4,2,fp1);
		   fseek(fp1,8+8*44050+offset,0);
           int j;
           for(j=0;j<vector1.size();j++)
		   {
              f1=float(vector1.at(j))/n;
			  strindex.copy(str3,m,m*j); 
              index=atoi(str3);
			  fwrite(&index,4,1,fp1);
			  fwrite(&f1,4,1,fp1);
		   }
		 } 
	}
    vector1.clear();
    fclose(fp1);
    fclose(fp);  
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -