c++实验室安全问题问题

热门日志推荐
人人最热标签
分享这篇日志的人常去
北京千橡网景科技发展有限公司:
文网文[号··京公网安备号·甲测资字
文化部监督电子邮箱:wlwh@··
文明办网文明上网举报电话: 举报邮箱:&&&&&&&&&&&&
请输入手机号,完成注册
请输入验证码
密码必须由6-20个字符组成
下载人人客户端
品评校花校草,体验校园广场C++实验题_百度知道
1. Write a function print() that prints a vector of ints to cout. Give it two arguments: a string for &labeling& the output and a vector.2. Create a vector of Fibonacci numbers and print them using the function from exercise 1. To create the vector, write a function, fibonacci(x,y,v, n), where integers x and y are ints, v is an empty vector&int&, and n is the number of el v[0] will be x and v[1] will be y. A Fibonacci number is one that is part of a sequence where each element is the sum of the two previous ones. For example, starting with 1 and 1, we get 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233….. Your fibonacci() function should make such a series starting with its x and y arguments.3. Write two functions that reverse the order of elements in a vector&int&. For example, 1, 3, 5, 7, 9 becomes 9, 7, 5, 3, 1. The first reverse function should produce a new vector with the reversed sequence, leaving its original vector unchanged. The other reverse function should reverse the elements of its vector without using any other vectors (hint: swap).4. Here is another mathematical problem, where the trick is as much to discover the algorithm as it is to write the code: write a program to display all possible permutations of a given input string--if the string contains duplicate characters, you may have multiple repeated results. Input should be of the form permute string and output should be a word per line.Here is a sample for the input cat:catctaactatctactca
提问者采纳
第题:#include&iostream&#include&string&#include&vector&//定义输函数 print(string s,vector&int& p){ cout&&s&& for(vector&int&::const_iterator t=p.begin();t!=p.end();t++)
cout&&*t&&& &;}int main(){ string s=&abc&; vector&int& a.clear(); for (vector&int&::size_type ix=0;ix!=10;ix++) {
a.push_back(ix); } print(s,a); cout&&}第二题:#include&iostream&#include &vector&fibonacci(int x,int y,vector&int& v,int n){ v.push_back(x); v.push_back(y); for(int m=2;m&n;m++) {
v.push_back(v[m-1]+v[m-2]);
for(int p=0; p&n; p++)
cout&&v[p]&&& &;
}int main(){ vector&int& it.clear(); fibonacci(1,1,it,20); cout&&}
第三题:#include &iostream&#include &vector&paixu(vector&int& m_vPaixu){ int vector_ vector_upper=m_vPaixu.size(); vector&int& m_vTMP; m_vTMP.clear();
for(int i=0;i&vector_i++) {
m_vTMP.push_back( m_vPaixu[vector_upper-i-1]);
cout&&m_vTMP[i]&& } cout&& m_vPaixu.clear();
for(int t=0;t&m_vTMP.size();t++) {
m_vPaixu.push_back(m_vTMP[t]);
cout&&m_vPaixu[t]&&
} cout&& return 0;}int main(){
int array[5]={1,3,5,7,9};
vector&int& it(array,array+5); //cout&&it[ix]; paixu(it); }第四题:#include&iostream&//交换元素值void Swap(char &a,char &b){
b=}//全排列函数void Permutation(char string[],int start,int end){
if(start==end)
cout&&string&&& &;
for(int i=i&=i++)
Swap(string[i],string[start]);
Permutation(string,start+1,end);
Swap(string[i],string[start]);
}}void main(){
char string[]=&abcd&;
int len=strlen(string);
Permutation(string,0,len-1); cout&&
提问者评价
其他类似问题
为您推荐:
您可能关注的推广
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁高分悬赏C++实验题目关于文件搜索系统的_百度知道
高分悬赏C++实验题目关于文件搜索系统的
发本文件搜索系统输入路径能列该路径文件目录目录空提示目录没文件txt文件要求能显示文件等属性并且能够读文件显示编辑框其进行修改并保存用C++编
注解尽量详细些
要用Demo哦
谁给答案我再追加
简单查阅知识:stat结构体dirent结构体目录指针DIR打目录函数opendir目录读取函数:readdir等面c语言 看看吧希望所帮助概思路打目录循环读取目录获文件通stat获取文件状态(权限等) mode_ char buf[1024]; DIR * struct dirent *
dp=opendir(&.&); if (dp==NULL) {
return -1; } while ((link=readdir(dp))!=0) {
if (lstat(link-&d_name, &sbuf)==-1)
if (strcmp(link-&d_name, &.&) == 0 || strcmp(link-&d_name, &..&) == 0)
mode=sbuf.st_
char perms[] = &----------&;
perms[0]='?';
switch (mode & S_IFMT)
case S_IFREG:
perms[0] = '-';
case S_IFDIR:
perms[0] = 'd';
case S_IFLNK:
perms[0] = 'l';
case S_IFIFO:
perms[0] = 'p';
case S_IFSOCK:
perms[0] = 's';
case S_IFCHR:
perms[0] = 'c';
case S_IFBLK:
perms[0] = 'b';
if (S_IRUSR
perms[1] = 'r';
if (S_IWUSR
perms[2] = 'w';
if (mode & S_IXUSR)
perms[3] = 'x';
if (mode & S_IRGRP)
perms[4] = 'r';
if (mode & S_IWGRP)
perms[5] = 'w';
if (mode & S_IXGRP)
perms[6] = 'x';
if (mode & S_IROTH)
perms[7] = 'r';
if (mode & S_IWOTH)
perms[8] = 'w';
if (mode & S_IXOTH)
perms[9] = 'x';
perms[10] = '\0';
int off=0;
memset(buf,0,sizeof(buf));
off += sprintf(buf+off, &%s &,perms);
off += sprintf (buf + off, & %3d %-8d %-8d &,sbuf.st_nlink, sbuf.st_uid, sbuf.st_gid);
off+=sprintf(buf + off, &%8lu &, (unsigned long)sbuf.st_size);char* p_date_format = &%b %e %H:%M&;
char datebuf[13]={0};
struct tm* p_
p_tm = localtime(&sbuf.st_mtime);
strftime(datebuf, sizeof(datebuf), p_date_format, p_tm);
off += sprintf (buf + off, &%s &, datebuf);
if (S_ISLNK(sbuf.st_mode))
char tmp[1024]={0};
readlink(link-&d_name,tmp,sizeof(tmp));
off += sprintf (buf + off, &%s -& %s&, link-&d_name,tmp);
off += sprintf (buf + off, &%s&, link-&d_name);
off += sprintf (buf + off, &%s&, &\r\n&);
其他类似问题
为您推荐:
其他1条回答
windows操作系统简单调用几api函数
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁C++实验答案_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
C++实验答案
上传于||暂无简介
阅读已结束,如果下载本文需要使用
想免费下载本文?
下载文档到电脑,查找使用更方便
还剩16页未读,继续阅读
你可能喜欢

我要回帖

更多关于 八皇后问题实验报告 的文章

 

随机推荐