
跪求解一道C/C++的程序题 谢谢
题目:求一个数列(无序)的最大单增子串长度。例如:1,2,5,8,6,7它的最大单增子串是1,2,5,6,7长度为5仅需给出长度所有东西都是从一个文件中读出,然后输出到另...
题目:求一个数列(无序)的最大单增子串长度。
例如:1,2,5,8,6,7 它的最大单增子串是1,2,5,6,7 长度为5
仅需给出长度
所有东西都是从一个文件中读出,然后输出到另一个文件中
摆脱各位高人了 小弟不胜感激 展开
例如:1,2,5,8,6,7 它的最大单增子串是1,2,5,6,7 长度为5
仅需给出长度
所有东西都是从一个文件中读出,然后输出到另一个文件中
摆脱各位高人了 小弟不胜感激 展开
1个回答
展开全部
#include <fstream.h>
#include <iostream.h>
int GetNum(ifstream *F)
{
unsigned char tmp;
int r,fin=0;
while(F->eof()==0 && fin<2)
{
if(fin==0)
{
*F>>tmp;
if(tmp-'0'<10)
{
r=tmp-'0';
fin=1;
}
}
else
{
(*F)>>tmp;
if((unsigned char)(tmp-'0')<10 && F->eof()==0)
{
r=r*10+(tmp-'0');
}
else
{
fin=2;
}
}
}
if(fin==0)
{
r=INT_MIN;
}
return r;
}
int main(int argc, char* argv[])
{
if(argc<2)
{
cout<<"Too few parameters"<<endl;
cout<<"Format: Count InputFile OutputFile"<<endl;
cout<<"Example: Count a.txt b.txt,then load a.txt then output the result to b.txt";
return 0;
}
ifstream IFile;
ofstream OFile;
IFile.open(argv[1],NULL);
OFile.open(argv[2],NULL);
int in[2],out,tmp;
char r;
in[1]=GetNum(&IFile);
while((tmp=GetNum(&IFile))!=INT_MIN)
{
in[0]=in[1];
in[1]=tmp;
out=in[1]-in[0];
if(out<0)
{
OFile<<'-';
out=-out;
}
while(out!=0)
{
r=out%10+'0';
out/=10;
OFile<<r;
}
OFile<<',';
}
IFile.close();
OFile.close();
return 0;
}
borland C++ 编译通过
#include <iostream.h>
int GetNum(ifstream *F)
{
unsigned char tmp;
int r,fin=0;
while(F->eof()==0 && fin<2)
{
if(fin==0)
{
*F>>tmp;
if(tmp-'0'<10)
{
r=tmp-'0';
fin=1;
}
}
else
{
(*F)>>tmp;
if((unsigned char)(tmp-'0')<10 && F->eof()==0)
{
r=r*10+(tmp-'0');
}
else
{
fin=2;
}
}
}
if(fin==0)
{
r=INT_MIN;
}
return r;
}
int main(int argc, char* argv[])
{
if(argc<2)
{
cout<<"Too few parameters"<<endl;
cout<<"Format: Count InputFile OutputFile"<<endl;
cout<<"Example: Count a.txt b.txt,then load a.txt then output the result to b.txt";
return 0;
}
ifstream IFile;
ofstream OFile;
IFile.open(argv[1],NULL);
OFile.open(argv[2],NULL);
int in[2],out,tmp;
char r;
in[1]=GetNum(&IFile);
while((tmp=GetNum(&IFile))!=INT_MIN)
{
in[0]=in[1];
in[1]=tmp;
out=in[1]-in[0];
if(out<0)
{
OFile<<'-';
out=-out;
}
while(out!=0)
{
r=out%10+'0';
out/=10;
OFile<<r;
}
OFile<<',';
}
IFile.close();
OFile.close();
return 0;
}
borland C++ 编译通过

2023-06-12 广告
单片机,即单片微控制器,也称为单片微型计算机,是将中央处理器(CPU)、存储器(ROM,RAM)、输入/输出接口和其他功能部件集成在一块 在一个小块的集成电路上,从而实现对整个电路或系统的数字式控制。单片机不是完成某一个逻辑功能的芯片,而是...
点击进入详情页
本回答由意法半导体(中国)投资有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询