第6章  使用库算法


本章中主要教我们怎样使用几个库算法来解决与处理字符串和学生成绩相关的问题。
1、分析字符串
使用一个循环来连接两幅字符图案
<span style="font-family:KaiTi_GB2312;">for(vector<string>::const_iterator it = bottom.begin(); it != bottom.end(); ++it)
ret.push_back(*it);</span></span>

等价于

<span style="font-family:KaiTi_GB2312;">ret.insert(ret.end(), bottom.begin(), bottom.end());</span></span>

也等价于


<span style="font-family:KaiTi_GB2312;">copy(bottom.begin(), bottom.end(), back_inserter(ret));</span></span>

分析:这里指的是复制了bottom中的全部的元素而且把它们加入到ret的末尾。

在这个函数借宿之后。ret的长度将加入bottom.size()。


补充:back_inserter(c) 对容器c产生一个迭代器,这个迭代器会给c加入元素。这个容器必须支持链表,向量以及字符串类型都会支持push_back操作。
copy(b, e, d) 把[b,e)所指示的系列拷贝到由d指示的目的地中。



2、实现split的方法
<span style="font-family:KaiTi_GB2312;">//假设參数是空白区域则为true。否则为false
bool space(char c)
{
return isspace(c);
} //假设參数是空白区域则为false。否则为true
bool not_space(char c)
{
return !isspace(c);
} vector<string> split(const string& str)
{
typedef string::const_interator iter;
vector<string> ret; iter != str.begin();
while(i != str.end())
{
//忽略前端空白
i = find_if(i, str.end(), not_space); //找到下一个单词的结尾
iter j = find_if(i, str.end(), space); //复制在[i,j)中的字符
if(i != str.end())
ret.push_back(string(i,j));
i = j;
}
return ret;
}</span></span>

补充:

find_if(b,e,p)  依据谓词p来检查每个元素;find(b,e,t) 在序列中查找一个特定值的算法。

3、回文
回文就是顺读和逆读都一样的单词。
<span style="font-family:KaiTi_GB2312;">// lesson6.2.cpp : 定义控制台应用程序的入口点。
//功能:推断回文
//2014.5.22 #include "stdafx.h"
#include <algorithm>
#include <cctype>
#include <iostream>
#include <string> using namespace std; bool is_palindrome(const string& s)
{
return equal(s.begin(), s.end(), s.rbegin());
} int _tmain(int argc, _TCHAR* argv[])
{
string s;
while (cin >> s)
{
if (is_palindrome(s))
cout << s << " is a palindrome" << endl;
else
cout << s << " is not a palindrome" << endl;
}
return 0;
}</span></span>

执行结果:



程序分析:rbegin返回一个迭代器。这个迭代器会从容器的最后一个元素開始。而且从后向前地逆向訪问容器。

4、查找URL
一个URL(统一资源地址)的字符序列:protocol-name://resource-name

主函数:
<span style="font-family:KaiTi_GB2312;">// lesson6_1.cpp : 定义控制台应用程序的入口点。
//功能:查找URL
//时间:2014.5.22 #include "stdafx.h"
#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>
#include <vector> #include "urls.h" using namespace std; int _tmain(int argc, _TCHAR* argv[])
{
string s;
while (getline(cin,s))
{
vector<string> v = find_urls(s);
for(vector<string>::const_iterator i = v.begin(); i != v.end(); ++i)
cout << *i << endl;
}
return 0;
}
</span></span>

程序分析:getline(is,s) 从is读一行输入并把它储存在s中

urls头文件:

<span style="font-family:KaiTi_GB2312;">#ifndef GUARD_urls_h
#define GUARD_urls_h #include <vector>
#include <string> std::vector<std::string> find_urls(const std::string& s); #endif</span></span>

urls源文件:

<span style="font-family:KaiTi_GB2312;">#include <algorithm>
#include <cctype>
#include <string>
#include <vector> #include "urls.h" using std::find;
using std::find_if; #ifndef _MSC_VER
using std::isalnum;
using std::isalpha;
using std::isdigit;
#endif using std::search;
using std::string;
using std::vector; bool not_url_char(char); string::const_iterator
url_end(string::const_iterator, string::const_iterator); string::const_iterator
url_beg(string::const_iterator, string::const_iterator); vector<string> find_urls(const string& s)
{
vector<string> ret;
typedef string::const_iterator iter;
iter b = s.begin(), e = s.end(); // 检查整个输入
while (b != e)
{
// 查找一个或多个紧跟://的字母
b = url_beg(b, e); // 假设查找成功
if (b != e)
{
// 获取URL的其余部分
iter after = url_end(b, e); // 记住这个URL
ret.push_back(string(b, after)); // 将b向前推进并查找位于本行中的其它的URL
b = after;
}
} return ret;
} //调用url_end目的是为了找出这个URL的结尾
string::const_iterator
url_end(string::const_iterator b, string::const_iterator e)
{
return find_if(b, e, not_url_char);
} //编写这个not_url_char的谓词
bool not_url_char(char c) {
// 除去字母数字之外,其它有可能出如今一个URL中的字符
static const string url_ch = "~;/? :@=&$-_.+!*'(),"; // 看c是否出如今一个URL并返回求反的结果
return !(isalnum(c) || find(url_ch.begin(), url_ch.end(), c) != url_ch.end()); //补充:isalnum函数是检验它的參数是否是一个字母数字字符(一个字母或者一个数字)
} //负责识别是否有一个有效的URL,我们必须保证在://分隔符之前有一个或多个的字母。并且在它的后面至少有一个字符。
string::const_iterator
url_beg(string::const_iterator b, string::const_iterator e)
{
static const string sep = "://"; typedef string::const_iterator iter; // `i' 标记了查找到的分隔符的位置
iter i = b; while ((i = search(i, e, sep.begin(), sep.end())) != e)
{
//确保切割符不是本行中唯一的一个符号
if (i != b && i + sep.size() != e)
{ // `beg标记协议名称的开关
iter beg = i;
while (beg != b && isalpha(beg[-1])) //isalpha 推断不是字母
--beg; // 在分隔符前面以及后面至少有一个字符吗?
if (beg != i && !not_url_char(i[sep.size()]))
return beg;
} //我们找到的分隔符不是一个URL的一部分
if(i != e)
i += sep.size();
} return e;
}</span></span>

执行结果:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdG9feGlkaWFuaHBoX3lvdXRo/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">


程序分析:
1)isalnum函数是检验它的參数是否是一个字母数字字符(一个字母或者一个数字);
2)isalpha 推断不是字母。

3)search(b,e,b2,e2) 在序列[b,e)中查找一个特定的算法,查找由[b2,e2)所指示的序列。

6、对计算成绩的方案进行比較
编敲代码解决以下两个不同的问题:
1)读所有学生的记录。把做了所有家庭作业的学生与其它的学生分隔开
2)对每一组中的全部学生分别使用每个的计算成绩的方案,报告每一组的中值成绩。

主函数:
<span style="font-family:KaiTi_GB2312;">// lesson6_3.cpp : 定义控制台应用程序的入口点。
//功能:计算成绩
//时间:2014.5.22 #include "stdafx.h"
#include <vector>
#include <iostream> #include "analysis.h"
#include "Student_info.h" using namespace std; int _tmain(int argc, _TCHAR* argv[])
{
//做以及没做家庭作业的学生
vector<Student_info> did,didnt; //读入学生记录并划分他们
Student_info student;
while(read(cin,student))
{
if(did_all_hw(student))
did.push_back(student);
else
didnt.push_back(student);
} //证实这些分析将向我们出示某些结果
if(did.empty())
{
cout << "No student did all the homework!" << endl;
return 1;
}
if(didnt.empty())
{
cout << "Every student did all the homework!" << endl;
return 1;
} //进行分析
write_analysis(cout, "median", median_analysis, did, didnt);
write_analysis(cout, "average", average_analysis, did, didnt);
write_analysis(cout, "median of homework turned in", optimistic_median_analysis, did, didnt); return 0;
}</span></span>

简单检查一个学生是否做个全部的家庭作业:
<span style="font-family:KaiTi_GB2312;">#include <algorithm>

#include "Student_info.h"

using namespace std;

//函数的目的就是查找储存在里面的全部值中是否有为0的
bool did_all_hw(const Student_info& s)
{
return((find(s.homework.begin(), s.homework.end(), 0)) == s.homework.end());
}</span></span>

不同的分析函数:

<span style="font-family:KaiTi_GB2312;">//功能:分析
//时间:2014.5.22
#include <slgorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <stdexcept>
#include <vector> #include "Student_info.h"
#include "grade.h"
#include "median.h" using namespace std; //建立一个辅助函数在grade内运行try语句而且处理异常
double grade_aux(const Student_info& s)
{
try
{
return grade(s);
}
catch(domain_error)
{
return grade(s.midterm, s.final, 0)
}
}
//median_analysis
double median_analysis(const vector<Student_info>& students)
{
vector<double> grades; transform(students.begin(), students.end(),back_inserter(grades), grade_aux); return median(grades);
} //使用一个分析例程来比較两个学生数据的集合
void write_analysis(ostream& out, const string& name, double analysis(const vector<Student_info>&), const vector<Student_info>& did, const vector<Student_info>& didnt)
{
out << name << ": median(did) = " << analysis(did) << ",median(didnt) = " << analysis(didnt) << endl;
} //计算家庭作业的平均成绩
double average(const vector<double>& v)
{
return accumulate(v.begin(), v.end(), 0.0) / v.size(); //这里一定要注意用0.0这样求出的值才不会丢了小数点部分
} //计算总成绩
double average_grade(const Student_info& s)
{
return grade(s.midterm, s.final, average(s.homework));
} //平均函数分析
double average_analysis(const vector<Student_info>& students)
{
vector<double> grades; transform(students.begin(), students.end(), back_inserter(grades), average_grade); return median(grades);
} //上交家庭作业的中值,s.homework的非零元素的中值,假设没有这种元素存在的话。则为0
double optimistic_median(const Student_info& s)
{
vector<double> nonzero;
remove_copy(s.homework.begin(), s.homework.end(), back_inserter(nonzero),0); if(nonzero.empty())
return grade(s.midterm, s.final, 0);
else
return grade(s.midterm, s.final, median(nonzero));
} //optimistic_median_analysis
double optimistic_median_analysis(const vector<Student_info>& students)
{
vector<double> grades; transform(students.begin(),students.end(), back_inserter(grades), optimistic_median); return median(grades);
}
</span></span>

程序分析:

1)accumulate(b,e,t)                 把区间[b,e)中的元素的总和加上t之后储存在t中,是在<numeric>中定义的。
2)find(b,e,t)                       在序列[b,e)中查找值t;
3)find_if(b,e,p)                    在序列[b,e)中依据谓词p来检查每个元素。
4)search(b,e,b2,e2)                 在序列[b,e)中查找一个特定的算法。查找由[b2,e2)所指示的序列;
5)copy(b,e,d)                       把序列[b,e)拷贝到由d指示的目的地中,复制整个序列;
6)remove_copy(b,e,d,t)              把序列[b,e)中全部不等于t的元素拷贝到由d指示的目的地中;
7)remove_copy_if(b,e,d,t)           把序列[b,e)中全部使谓词p为假的元素拷贝到由d指示的目的地中;
8)remove_if(b,e,p)                  使在区间[b,e)中使谓词p为假的元素位于这个域的头部,返回一个迭代器,这个迭代器指示了位于那些不被删除的元素之后的那个位置
9)remove(b,e,t)                     作用和上面那个一样,可是检測了哪些元素值不等于t;
10)transform(b,e,d,f)               依据域[b,e)中的元素执行函数f,把f的结果存储在d中;  

7、对学生进行分类并回想下我们的问题
1)使用两次传递的解决方式
<span style="font-family:KaiTi_GB2312;">#include <algorithm>
#include <iterator>
#include <vector> #include "Student_info.h"
#include "grade.h" using namespace std; vector<Student_info> extract_fails(vector<Student_info>& students)
{
vector<Student_info> fail;
remove_copy_if(students.begin(), students.end(),back_inserter(fail),pgrade); students.erase(remove_if(students.begin(),students.end(), fgrade), students.end()); return fail;
}</span></span>

这里计算了两次成绩。所以须要改进


2)一种一次传递的解决方式
<span style="font-family:KaiTi_GB2312;">#include <algorithm>
#include <vector> #include "Student_info.h"
#include "grade.h" using std::stable_partition;
using std::vector; vector<Student_info> extract_fails(vector<Student_info>& students)
{
vector<Student_info>::iterator iter = stable_partition(students.begin(), students.end(), pgrade);
vector<Student_info> fail(iter, students.end());
students.erase(iter, students.end()); return fail;
}</span></span>

程序分析:

1)partition(b,e,p)    以谓词p为基础从而划分在域[b,e)中的元素以使那些使谓词为真的元素处于容器的头部。

返回一个迭代器,这个迭代器指示了第一个令谓词为假的元素;

2)stable_partition(b,e,p)  会让在每个区域内的元素的输入顺序保持不变  


8、以下的这个程序片段做什么的?
<span style="font-family:KaiTi_GB2312;">vector<int> u(10,100);
vector<int> v;
copy(u.begin(), u.end(), v.begin());</span>

编写一个包括这个片段的程序并编译以及执行这个程序。

方法一:
<span style="font-family:KaiTi_GB2312;">// lesson6_5_1.cpp : 定义控制台应用程序的入口点。

//改进上面方法:利用迭代适配器,循环
//时间:2014.5.24 #include "stdafx.h"
#include <algorithm>
#include <iterator>
#include <vector> using namespace std; int _tmain(int argc, _TCHAR* argv[])
{
vector<int> u(10,100);
vector<int> v; copy(u.begin(),u.end(),inserter(v,v.begin()));
return 0;
}</span>

方法二:

<span style="font-family:KaiTi_GB2312;">// lesson6_5_2.cpp : 定义控制台应用程序的入口点。
//改进:使用最初的循环来做
//时间:2014.5.24 #include "stdafx.h"
#include <algorithm>
#include <vector> using namespace std; int _tmain(int argc, _TCHAR* argv[])
{
vector<int> u(10, 100);
vector<int> v; for(vector<int>::const_iterator it = u.begin(); it != u.end(); ++it)
v.push_back(*it);
return 0;
}
</span>

程序说明:vector<int> u(10,100)定义了一个vector u,该vector中存有10个100。将u中的元素通过copy函数所有拷贝到v。


9、计算成绩的分析程序的一部分功能是读入学生记录并对其进行分类。这一部分程序依赖于学生是否做了所有的家庭作业,这个问题和extract_fails中所须要解决的类似
<span style="font-family:KaiTi_GB2312;">// lesson6_6.cpp : 定义控制台应用程序的入口点。
//功能:计算成绩的分析程序的一部分功能是读入学生记录并对其进行分类。这一部分程序依赖于学生是否做了所有的家庭作业,这个问题和extract_fails中所须要解决的相似
//时间:2014.5.24 #include "stdafx.h"
#include <vector>
#include <iostream> #include "analysis.h"
#include "Student_info.h" using namespace std; //分类问题
vector<Student_info> extract_didnt(vector<Student_info>& input)
{
vector<Student_info>::iterator iter = stable_partition(input.begin(),input.end(),did_all_hw);
vector<Student_info> output(iter,input.end());
input.erase(iter, input.end()); return output;
} int _tmain(int argc, _TCHAR* argv[])
{
// students who did and didn't do all their homework
vector<Student_info> did; // read the student records and partition them
Student_info student;
while (read(cin, student))
did.push_back(student); vector<Student_info> didnt = extract_didnt(did); // verify that the analyses will show us something
if (did.empty())
{
cout << "No student did all the homework!" << endl;
return 1;
} if (didnt.empty())
{
cout << "Every student did all the homework!" << endl;
return 1;
} // do the analyses
write_analysis(cout, "median", median_analysis, did, didnt);
write_analysis(cout, "average", average_analysis, did, didnt);
write_analysis(cout, "median of homework turned in",
optimistic_median_analysis, did, didnt); return 0;
return 0;
}
</span>

程序说明:这里须要注意的就是stable_partition.


10、编写一个函数,用这个函数来依照你自己的选择准则来对学生进行分类,使用它来取代extract_fails程序从而对它进行測试
主函数:
<span style="font-family:KaiTi_GB2312;">// lesson6_7.cpp : 定义控制台应用程序的入口点。

//功能:编写一个函数。用这个函数来依照你自己的选择准则来对学生进行分类,使用它来取代extract_fails程序从而对它进行測试
//时间:2014.5.24 #include "stdafx.h"
#include <algorithm>
#include <vector>
#include <iostream>
#include <string> #include "6-7-classify.h"
#include "Student_info.h"
#include "grade.h" using namespace std; int _tmain(int argc, _TCHAR* argv[])
{
vector<Student_info> vs;
Student_info s;
string::size_type maxlen = 0;
while(read(cin,s))
{
maxlen = max(maxlen, s.name.size());
vs.push_back(s);
} sort(vs.begin(), vs.end(),compare); vector<Student_info> fails = classify(vs, pgrade); for(int i = 0; i < fails.size(); ++i)
cout << fails[i].name << " " << grade(fails[i]) << endl; return 0;
}
</span>

分类函数:

<span style="font-family:KaiTi_GB2312;">#include <algorithm>
#include "6-7-classify.h" using namespace std; //这就是依照自己的准则来分类
vector<Student_info> classify(vector<Student_info>& input, bool criteria(const Student_info&))
{
ector<Student_info>::iterator iter = stable_partition(input.begin(), input.end(), criteria);
vector<Student_info> output(iter, input.end());
input.erase(iter, input.end()); return output;
}</span>

11、在lesson6_7中继续编写一个函数在程序中用它来分析学生的成绩

主函数:
<span style="font-family:KaiTi_GB2312;">// lesson6_8.cpp : 定义控制台应用程序的入口点。

//功能:在lesson6_7中继续编写一个函数在程序中用它来分析学生的成绩

#include "stdafx.h"
#include <vector>
#include <iostream> #include "6-8-classify.h"
#include "analysis.h"
#include "Student_info.h" using namespace std; int _tmain(int argc, _TCHAR* argv[])
{
// students who did and didn't do all their homework
vector<Student_info> did; // read the student records and partition them
Student_info student;
while (read(cin, student))
did.push_back(student); vector<Student_info> didnt = classify(did, did_all_hw);//这里是我们的两点地方 // verify that the analyses will show us something
if (did.empty())
{
cout << "No student did all the homework!" << endl;
return 1;
} if (didnt.empty())
{
cout << "Every student did all the homework!" << endl;
return 1;
} // do the analyses
write_analysis(cout, "median", median_analysis, did, didnt);
write_analysis(cout, "average", average_analysis, did, didnt);
write_analysis(cout, "median of homework turned in",optimistic_median_analysis, did, didnt); return 0;
}
</span>

12、使用一个库算法连接一个vector<string>对象中的全部元素

<span style="font-family:KaiTi_GB2312;">// lesson6_9.cpp : 定义控制台应用程序的入口点。
//功能:使用一个库算法连接一个vector<string>对象中的全部元素
//时间:2014.5.24 #include "stdafx.h"
#include <vector>
#include <string>
#include <iostream>
#include <iterator>
#include <numeric> using namespace std; int _tmain(int argc, _TCHAR* argv[])
{
cout << "Please enter some words: ";
vector<string> v;
string s;
while(cin >> s)
v.push_back(s);
string sum = accumulate(v.begin(),v.end(),string("the string is:"));
cout << sum << endl;
return 0;
}
</span>

执行结果:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdG9feGlkaWFuaHBoX3lvdXRo/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">


                                                                                     ——To_捭阖_youth

Accelerated C++学习笔记7—&lt;使用库算法&gt;的更多相关文章

  1. seaJs学习笔记2 – seaJs组建库的使用

    原文地址:seaJs学习笔记2 – seaJs组建库的使用 我觉得学习新东西并不是会使用它就够了的,会使用仅仅代表你看懂了,理解了,二不代表你深入了,彻悟了它的精髓. 所以不断的学习将是源源不断. 最 ...

  2. python3.4学习笔记(八) Python第三方库安装与使用,包管理工具解惑

    python3.4学习笔记(八) Python第三方库安装与使用,包管理工具解惑 许多人在安装Python第三方库的时候, 经常会为一个问题困扰:到底应该下载什么格式的文件?当我们点开下载页时, 一般 ...

  3. openresty 学习笔记六:使用session库

    openresty 学习笔记六:使用session库 lua-resty-session 是一个面向 OpenResty 的安全和灵活的 session 库,它实现了 Secure Cookie Pr ...

  4. OpenCV学习笔记(27)KAZE 算法原理与源码分析(一)非线性扩散滤波

    http://blog.csdn.net/chenyusiyuan/article/details/8710462 OpenCV学习笔记(27)KAZE 算法原理与源码分析(一)非线性扩散滤波 201 ...

  5. 机器学习实战(Machine Learning in Action)学习笔记————06.k-均值聚类算法(kMeans)学习笔记

    机器学习实战(Machine Learning in Action)学习笔记————06.k-均值聚类算法(kMeans)学习笔记 关键字:k-均值.kMeans.聚类.非监督学习作者:米仓山下时间: ...

  6. 再探快速傅里叶变换(FFT)学习笔记(其三)(循环卷积的Bluestein算法+分治FFT+FFT的优化+任意模数NTT)

    再探快速傅里叶变换(FFT)学习笔记(其三)(循环卷积的Bluestein算法+分治FFT+FFT的优化+任意模数NTT) 目录 再探快速傅里叶变换(FFT)学习笔记(其三)(循环卷积的Blueste ...

  7. Linux学习笔记——如何使用共享库交叉编译

    0.前言     在较为复杂的项目中会利用到交叉编译得到的共享库(*.so文件).在这样的情况下便会产生下面疑问,比如:     [1]交叉编译时的共享库是否须要放置于目标板中,假设须要放置在哪个文件 ...

  8. HMM的学习笔记1:前向算法

    HMM的学习笔记 HMM是关于时序的概率模型.描写叙述由一个隐藏的马尔科夫链随机生成不可观測的状态随机序列,再由各个状态生成不可观測的状态随机序列,再由各个状态生成一个观測而产生观測的随机过程. HM ...

  9. jvm学习笔记一(垃圾回收算法)

    一:垃圾回收机制的原因 java中,当没有对象引用指向原先分配给某个对象的内存时候,该内存就成为了垃圾.JVM的一个系统级线程会自动释放该内存块.垃圾回收意味着程序不再需要的对象是"无用信息 ...

随机推荐

  1. Search a 2D Matrix leetcode java

    题目: Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the f ...

  2. 监听视图树 ViewTreeObserver 获取View的宽高

    前奏:在哪里可以获取到View的宽高 我们知道,在onCreate方法执行完毕以后,View才开始被测量,所以我们在onCreate方法里面通过view.getWidth()或view.getMeas ...

  3. WCF 添加 RESTful 支持,适用于 IIS、Winform、cmd 宿主

    You can expose the service in two different endpoints. the SOAP one can use the binding that support ...

  4. Win10 Docker 安装使用

    1.前言 Docker最近推出了可以运行在Win10和Mac上的稳定版本,让我们赶紧来体验一下. 2.安装准备 需要的条件为: 64bit Windows 10,开启Hyper-V 2.1 下载Doc ...

  5. IDA远程调试so库JNI_Onload函数

    JNI_OnLoad函数大概功能就是在程序加载so的时候,会执行JNI_OnLoad函数,做一系列的准备工作.很多时候,程序猿们会将一些重要信息放在此函数中,而不是通过某种事件来重复触发.包括说将反调 ...

  6. angular6 Can't bind to 'zzst' since it isn't a known property of

    文档: https://angular.io/guide/template-syntax#event-binding The Angular compiler may reject these bin ...

  7. leetcode第一刷_Integer to Roman

    这道题当时不会写,是參照discuss写的. 首先要弄明确罗马数字的规则,这个在国外难道是常识吗.为什么题干一点都没讲.. 4000以下一共同拥有以下几种符号:"M", " ...

  8. Python编程-Office操作-操作Excel(中)

    例子文件如下: 一些复杂的读取操作getCells.py import openpyxl wb = openpyxl.load_workbook('example.xlsx') sheet = wb. ...

  9. uva 701 - The Archeologists' Dilemma

    题目链接:uva 701 - The Archeologists' Dilemma 题目大意:给出x,求一个e,使得x * 10 ^ y ≤ 2 ^ e < (x + 1) * 10 ^ y. ...

  10. Java从零开始学二十五(枚举定义和简单使用)

    一.枚举 枚举是指由一组固定的常量组成的类型,表示特定的数据集合,只是在这个数据集合定义时,所有可能的值都是已知的. 枚举常量的名称建议大写. 枚举常量就是枚举的静态字段,枚举常量之间使用逗号隔开. ...