有两个C++程序,需要拜托人帮忙写一下,谢谢了!

 我来答
chujiangke001
2013-06-09 · TA获得超过1605个赞
知道小有建树答主
回答量:1352
采纳率:0%
帮助的人:814万
展开全部
第一个

#include <iostream>
#include <map>
#include <vector>
#include <fstream>
#include <sstream>
#include <string>
#include<algorithm>
#include<functional>
using namespace std;

int cmp(const pair<string,int> & x, const pair<string,int>& y)
{
return x.second > y.second;
}
int main()
{
map<string,int>::iterator it;
map<string,int> ma;

ifstream in("in.txt");// 读入的文件。
ofstream out("result.txt");

string str;
string st;

while( in>>st )
{
it=ma.find(st);
if( it!=ma.end() )
++(*it).second;
else
ma[st]=1;
}

vector< pair<string,int> > vec;

for( it=ma.begin(); it!=ma.end(); ++it )
{
vec.push_back(make_pair(it->first,it->second));
cout<<it->first<<it->second<<endl;
}
sort(vec.begin(),vec.end(),cmp); //要用vector< pair<string,int> > 转一次
cout<<"xiaojiba"<<endl;、
vector<pair<string,int> > ::iterator ivec=vec.begin();
while(ivec!=vec.end())
{
cout<< ivec->first<<" "<<ivec->second<<endl;
out<<ivec->first<<" "<<ivec->second<<endl;
ivec++;
}

//cout<<(*it).first<<" "<<(*it).second<<endl;
return 0;
}
追问
第二个很麻烦的在于怎么浏览目录下的文件呢?主要是第二个有些问题,再次感谢!
追答

第二个。俺们调用是用的linux 的shell借口。

你可以吧du-k 改成tree命令。

#include<iostream>

#include<cstdlib>

#include<string>

#include<cstring>

#include<fstream>

using namespace std;


int  main(int argc,  char* argv[])

{

   for (int i = 0; i<argc; i++)

            cout<<argv[i]<<endl;

  cout << "mysh# ";


  cout<<"input filename"<<endl;

  string filename;

  cin>>filename;

  string cmd="du -k "+filename+">xiaojiba.txt";

  system(const_cast<char*>(cmd.c_str()));

  int count=0;

  string temp;

  string filelocate=filename+"/xiaojiba.txt";

  cout<<filelocate<<endl;

  ifstream infile(filelocate.c_str());

  while(infile >> temp)

  {

  count++;

  cout<<temp<<endl;

  }


  cout<<"the number of file is: "<<(count-1)/2<<endl;

  cout << "\n";

  return 0;

}

xu水冰淼
2013-06-09
知道答主
回答量:40
采纳率:0%
帮助的人:19.7万
展开全部
希望有人给代码,我也一起等着瞅代码。。。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式