#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)