| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 749 人关注过本帖
标题:[菜鸟求助]瞧一瞧,看一看啊,,菜鸟又有新问题啦,答对没奖啦,,答错打屁屁啦,,
只看楼主 加入收藏
dlcdavid
Rank: 3Rank: 3
来 自:成都
等 级:新手上路
威 望:6
帖 子:193
专家分:0
注 册:2005-12-23
收藏
 问题点数:0 回复次数:5 
[菜鸟求助]瞧一瞧,看一看啊,,菜鸟又有新问题啦,答对没奖啦,,答错打屁屁啦,,

#include <fstream>
#include <vector>
#include <list>
#include <algorithm>
这几个文件里有什么东西啊???

using namespace std;
拿来做什么啊???

vector<float> xxxxxxxxx
这是什么啊??有什么用啊???
最后请有空的大侠帮个忙,,,,翻译一下嘛,,,,,算24的,,,,,为什么他里面有些输出用的printf...输出的结果小数点后面有8个0,是不是把%f删了就行了???
char charnumber4[20] = "";
sprintf(charnumber4, "%f", num4);
string number4=charnumber4;
可以说一下嘛,最好重新帮小弟改一下,,,有更好看的这个程序发上来更好啊...
上面的问题都来自这个程序
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
using namespace std;

int result_set_generation(float, float, float, float);

int main()
{
float num1, num2, num3, num4;

cout << "enter number1 ";
cin >> num1;
cout << "enter number2 ";
cin >> num2;
cout << "enter number3 ";
cin >> num3;
cout << "enter number4 ";
cin >> num4;

result_set_generation(num1, num2, num3, num4);
result_set_generation(num1, num2, num4, num3);
result_set_generation(num1, num3, num2, num4);
result_set_generation(num1, num3, num4, num2);
result_set_generation(num1, num4, num3, num2);
result_set_generation(num1, num4, num2, num3);

result_set_generation(num2, num3, num1, num4);
result_set_generation(num2, num3, num4, num1);
result_set_generation(num2, num4, num1, num3);
result_set_generation(num2, num4, num3, num1);

result_set_generation(num3, num4, num1, num2);
result_set_generation(num3, num4, num2, num1);

return 0;
}

int result_set_generation(float num1, float num2, float num3, float num4)
{
vector<float> first_result;
vector<float> second_result;
vector<float> third_result;
vector<string> firstexp;
vector<string> secondexp;
vector<string> thirdexp;

string expression;

float first1, first2, first3, first4, first5, first6;
float second;
float third;

first1=num1+num2;
first2=num1-num2;
first3=num2-num1;
first4=num1*num2;
first5=num1/num2;
first6=num2/num1;

char charnumber1[20] = "";
sprintf(charnumber1, "%f", num1);
string number1=charnumber1;
char charnumber2[20] = "";
sprintf(charnumber2, "%f", num2);
string number2=charnumber2;
char charnumber3[20] = "";
sprintf(charnumber3, "%f", num3);
string number3=charnumber3;
char charnumber4[20] = "";
sprintf(charnumber4, "%f", num4);
string number4=charnumber4;

expression=number1+"+"+number2;
firstexp.push_back(expression);
expression=number1+"-"+number2;
firstexp.push_back(expression);
expression=number2+"-"+number1;
firstexp.push_back(expression);
expression=number1+"*"+number2;
firstexp.push_back(expression);
expression=number1+"/"+number2;
firstexp.push_back(expression);
expression=number2+"/"+number1;
firstexp.push_back(expression);

first_result.push_back(first1);
first_result.push_back(first2);
first_result.push_back(first3);
first_result.push_back(first4);
first_result.push_back(first5);
first_result.push_back(first6);


for (int i=0; i<6; i++)
{
second=first_result[i]+num3;
second_result.push_back(second);
expression="("+firstexp[i]+")"+"+"+number3;
secondexp.push_back(expression);

second=first_result[i]-num3;
second_result.push_back(second);
expression="("+firstexp[i]+")"+"-"+number3;
secondexp.push_back(expression);

second=num3-first_result[i];
second_result.push_back(second);
expression=number3+"-"+"("+firstexp[i]+")";
secondexp.push_back(expression);

second=first_result[i]*num3;
second_result.push_back(second);
expression="("+firstexp[i]+")"+"*"+number3;
secondexp.push_back(expression);

second=first_result[i]/num3;
second_result.push_back(second);
expression="("+firstexp[i]+")"+"/"+number3;
secondexp.push_back(expression);

second=num3/first_result[i];
second_result.push_back(second);
expression=number3+"/"+"("+firstexp[i]+")";
secondexp.push_back(expression);
}

for (i=0; i<36; i++)
{
third=second_result[i]+num4;
third_result.push_back(third);
expression="("+secondexp[i]+")"+"+"+number4;
thirdexp.push_back(expression);

third=second_result[i]-num4;
third_result.push_back(third);
expression="("+secondexp[i]+")"+"-"+number4;
thirdexp.push_back(expression);

third=num4-second_result[i];
third_result.push_back(third);
expression=number4+"-"+"("+secondexp[i]+")";
thirdexp.push_back(expression);

third=second_result[i]*num4;
third_result.push_back(third);
expression="("+secondexp[i]+")"+"*"+number4;
thirdexp.push_back(expression);

third=second_result[i]/num4;
third_result.push_back(third);
expression="("+secondexp[i]+")"+"/"+number4;
thirdexp.push_back(expression);

third=num4/second_result[i];
third_result.push_back(third);
expression=number4+"/"+"("+secondexp[i]+")";
thirdexp.push_back(expression);
}

vector<float>::iterator p = third_result.begin();
vector<string>::iterator j=thirdexp.begin();
while(p!=third_result.end())
{
if(*p==24)
cout<<*j<<endl;
p++;
j++;
}

return 0;
};


他警告:
--------------------Configuration: Cpp1 - Win32 Debug--------------------
Compiling...
Cpp1.cpp
C:\Documents and Settings\user_child\桌面\算24的C程序\新建文件夹\Cpp1.cpp(175) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,std::basic_string<char,std::char_traits<char>,std::al
locator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,int>' : identifier was truncated to '255' characters in the debug information
C:\Documents and Settings\user_child\桌面\算24的C程序\新建文件夹\Cpp1.cpp(175) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,std::basic_string<char,std::char_traits<char>,std::allocato
r<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> > &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,int>' : identifier was truncated to '255' characters in the debug information
d:\download\vc98\include\vector(39) : warning C4786: 'std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >::vector<std::basic_string<
char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >' : identifier was truncated to '255' characters in the debug information
d:\download\vc98\include\vector(60) : warning C4786: 'std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >::~vector<std::basic_string
<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >' : identifier was truncated to '255' characters in the debug information
Linking...

Cpp1.exe - 0 error(s), 4 warning(s)

搜索更多相关主题的帖子: 打屁 include vector 答对 
2005-12-26 21:56
ElfDN
Rank: 4
等 级:贵宾
威 望:11
帖 子:291
专家分:0
注 册:2005-11-13
收藏
得分:0 
#include <fstream>
这个是文件流操作的头文件
#include <vector>
这个是向量的头文件
#include <list>
这个是链表的头文件
#include <algorithm>
这个是算法的头文件,一般用到的是swap和sort
using namespace std;
这个是申请名字空间的,标准C++的东西,看看简单的书就知道了
vector<float> xxxxxxxxx
这个是一个浮点数的向量,相当与一个不定长数组,功能比数组强

2005-12-27 22:56
corrupt
Rank: 2
等 级:新手上路
威 望:3
帖 子:535
专家分:0
注 册:2004-9-29
收藏
得分:0 

用到了 stl的 标准函数库, 楼主可以好好学stl,
原代码 相当不错的
你这个程序,其实应该是 很不错的了~~


2005-12-28 08:40
dlcdavid
Rank: 3Rank: 3
来 自:成都
等 级:新手上路
威 望:6
帖 子:193
专家分:0
注 册:2005-12-23
收藏
得分:0 
申明,,这不是我的程序,,呵呵,,不然我哪来的问题嘛
我就爱拿现成的程序来分析,,
我觉得比看书有用

为了C++,我放弃了课本
为了高考,我又放弃了C++
现在而今眼目下,我能做什么?www.
2005-12-28 22:24
corrupt
Rank: 2
等 级:新手上路
威 望:3
帖 子:535
专家分:0
注 册:2004-9-29
收藏
得分:0 
楼上的观点 我同意 一 部分
分析 别人的代码, 你要有起码的知识点啊..
接着吸收 别人的解决问题的思维~~

2005-12-29 09:25
dlcdavid
Rank: 3Rank: 3
来 自:成都
等 级:新手上路
威 望:6
帖 子:193
专家分:0
注 册:2005-12-23
收藏
得分:0 
stl是什么哦??????嘎嘎,,,

为了C++,我放弃了课本
为了高考,我又放弃了C++
现在而今眼目下,我能做什么?www.
2005-12-30 23:03
快速回复:[菜鸟求助]瞧一瞧,看一看啊,,菜鸟又有新问题啦,答对没奖啦,,答错打屁屁 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.035671 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved