文章目录
复习:树怎么写
复习:文件输入输出
输入:
FILE *fp=NULL;//定义指针
fp=fopen("input.txt","r");//打开文件
//fscanf(fp,"%d",&k);//这句会正常读入
//k=fgetc(fp);//这句类似于getchar()读入一个字符,若k为int,则返回该字符的ASCII码
输出:
//类似地,fprintf类似于printf,fputc类似于putchar
fprintf(fp_output,"%d %d %d",max,start[max_end_pos],a[max_end_pos]);
//fputs类似于puts,只不过和fprintf参数位置有点不同,这里文件流fp是第二个参数
fputs("This is testing for fputs...\n", fp);
关闭文件:程序的最后一定记得close文件
fclose(fp);
fclose(fp_output);
复习:vector等stl的写法(vector最常用)
感想:
我开始有点无语了,stl的map,set,string等等(其他的还没用到)还挺好用的,但是vector也太难用了吧!!如果用vector的iterator方式访问,就很难对其它数组的下标相同的地方赋值,因为这两个迭代器分属于两个vector。那还是用下标访问方式比较好!
但是既然用了下标,还不如像我之前写的那样直接开辟数组。
现在看来,vector只有普通数组超内存的时候比较好用,或者是邻接矩阵存图?(我还没用过)
目前为止,我还是用普通数组吧!
#include<stdio.h>
#include<vector>
#include<map>
using namespace std;
//vector<int> fa;
vector<int> stripe;
map<int,int> fa;
vector<int> dp;
int main(){
FILE *fp=fopen("input.txt","r");
int n,m,l;
fscanf(fp,"%d",&n);
fscanf(fp,"%d",&m);
for(int i=1;i<=m;i++){
int temp;
fscanf(fp,"%d",&temp);
fa[temp]=i;
}
fscanf(fp,"%d",&l);
for(int i=0;i<l;i++){
int temp;
fscanf(fp,"%d",&temp);
map<int,int>:: iterator it=fa.find(temp);
stripe.push_back(it -> second);
}
dp.push_back(1);
for(vector<int>::iterator it=stripe.begin();it!=stripe.end();it++){
for(vector<int>::iterator i=stripe.begin();i!=it;i++){
vector<int>::iterator k=dp.
if(*it>*i&&dp)
}
}
}