请帮忙看一下如何编以下程序
这里有一个1.txt文件,里面有:
0.74 0.19 0.07
0.50 0.40 0.10
0.43 0.34 0.22
0.54 0.28 0.18
0.54 0.28 0.18
0.46 0.34 0.20
0.52 0.28 0.20
0.59 0.26 0.15
0.48 0.31 0.21
0.48 0.30 0.22
0.44 0.29 0.27
0.43 0.30 0.27
0.51 0.28 0.21
0.58 0.25 0.18
这些数,标记每行第一个数为3,标记每行第二个数为0,第三个数为1
然后又有一个2.txt的文件里面有:
03013133330133
03013133330033
03013133133333
03013133130333
03013133033333
03013133033033
03013133031333
03013133030333
03013033331333
03013033330133
03013033133333
03013033131333
03013033130333
03013033031333
03003133330333
01133333031033
01133333030033
01033333331013
01033333331003
01033333330013
01033333133003
。
有这些数,比如其中一行01033333133003 ,前四个数字0103用刚才第一个文件所约定的方法表示了4个数.意思是把刚才.txt1的第一行第二个数乘以第二行的第三个数乘以第三行第二个数。。然后把乘积附到这个文件每行的末尾编程环境为vc谢谢
这里有一个1.txt文件,里面有:
0.74 0.19 0.07
0.50 0.40 0.10
0.43 0.34 0.22
0.54 0.28 0.18
0.54 0.28 0.18
0.46 0.34 0.20
0.52 0.28 0.20
0.59 0.26 0.15
0.48 0.31 0.21
0.48 0.30 0.22
0.44 0.29 0.27
0.43 0.30 0.27
0.51 0.28 0.21
0.58 0.25 0.18
这些数,标记每行第一个数为3,标记每行第二个数为0,第三个数为1
然后又有一个2.txt的文件里面有:
03013133330133
03013133330033
03013133133333
03013133130333
03013133033333
03013133033033
03013133031333
03013133030333
03013033331333
03013033330133
03013033133333
03013033131333
03013033130333
03013033031333
03003133330333
01133333031033
01133333030033
01033333331013
01033333331003
01033333330013
01033333133003
。
有这些数,比如其中一行01033333133003 ,前四个数字0103用刚才第一个文件所约定的方法表示了4个数.意思是把刚才.txt1的第一行第二个数乘以第二行的第三个数乘以第三行第二个数。。然后把乘积附到这个文件每行的末尾编程环境为vc谢谢
解决方案 »
- ms的wininet文档的错误或者含糊不清,还有国外网友的错误跟风,让我搞一个问题搞了1周。就快放弃的时候,不小心就解决了。
- 关于Tab Control 控件
- 如何实现启动主窗口前要求用户身份认证!
- 项目外包,有意者先报价。
- 请推荐一本初学vc++的书
- 为什么总是报MFC apps must not #include <windows.h>的错误
- 有关CPU利用率的问题?马上给分!参与者均有分
- ODBC的问题,帮帮我,就剩5分了
- 高分求助:关于FormatRange函数的问题??急!!!
- CPropertyPage中调用UpdateData 显示试图执行系统不支持的操作
- 散分:对设计模式感兴趣的朋友,请进这个QQ群!
- COM 注册失败问题
void CMyDlg::OnBnClickedButton4()
{
CStdioFile sf1;
CStdioFile sf2;
sf1.Open("1.txt",CFile::modeRead);
sf2.Open("2.txt",CFile::modeRead);
CString s;
double input[14][3];
int i = 0;
while(sf1.ReadString(s))
{
Parse(s,input[i++]); //解析字符串转换成双精度数
} CStdioFile sf3;
sf3.Open("3.txt",CFile::modeCreate | CFile::modeWrite);
int pos[15];
CString tmp;
while(sf2.ReadString(s))
{
Parse2(s,pos); //解析字符串得到列表
tmp.Format("%e",Calc(input,pos)); //计算结果
sf3.WriteString(s + " " + tmp + "\r"); //输出到文件
} sf1.Close();
sf2.Close();
sf3.Close();
}int CMyDlg::Parse(const CString& str, double* input)
{
int pos1,pos2;
pos1 = str.Find(" ",0);
input[0] = atof(str.Left(pos1).GetBuffer());
pos2 = str.Find(" ",pos1 + 1);
input[1] = atof(str.Mid(pos1,pos2 - pos1 + 1));
input[2] = atof(str.Right(str.GetLength() - pos2));
return 0;
}int CMyDlg::Parse2(const CString& str, int* pos)
{
int cnt = str.GetLength();
CString s;
for(int i = 0; i < cnt; i++)
{
pos[i] = str[i] - '0';
}
return 0;
}double CMyDlg::Calc(double input[][3], int* pos)
{
int map[4] = {1,2,-1,0};
double res = 1.0f;
for(int i = 0; i < 14; i++)
{
res *= input[i][map[pos[i]]];
}
return res;
}
float f[MAX_COUNT][3]={0};
char ch,szText[MAX_COUNT+1] = {0};
int iCount, i = 0;
fp1 = fopen("1.txt","r");
if(NULL==fp1)goto exit;
fp2 = fopen("2.txt","r");
if(NULL==fp2)goto exit;
fp3 = fopen("3.txt","w");
if(NULL==fp3)goto exit; for(i=0;i<MAX_COUNT;++i)
{
if(3!=fscanf(fp1,"%f %f %f",&f[i][0],&f[i][1],&f[i][2]))break;
}
iCount = i;
while(iCount==fread(szText,1,iCount,fp2))
{
szText[i]=0;
float s = 1;
for(i=0;i<iCount;++i)
{
int iIndex = szText[i]=='3'?0:szText[i]-'0'+1;
if(iIndex>2)continue;//容易越界
s*=f[i][iIndex];
}
fprintf(fp3,"%f\n",s);
fseek(fp2,sizeof("\n"),SEEK_CUR);
};
exit:
if(fp1)fclose(fp1);fp1=NULL;
if(fp2)fclose(fp2);fp2=NULL;
if(fp3)fclose(fp3);fp3=NULL;
直接改为
fseek(fp2,2,SEEK_CUR);