![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
codeEval解题思路
文章平均质量分 65
jackycmu
我要成为一个优秀的googler
展开
-
SELF DESCRIBING NUMBERS题解
这一题要采用逆向思维,不要去判断每个数字出现的有没有这么多,而是去统计数字出现的次数,反过来构造出对应的描述数字,如果描述数字跟原来的数字相等,那就是self described的数#include #include #include using namespace std;string self_describe(string lineBuffer) { string res =原创 2013-12-29 02:47:01 · 724 阅读 · 0 评论 -
ROMAN NUMERALS 题解
这题还是比较tricky的,参考了戴方勤的leetcode版本的代码,radix的设计很巧妙,900,400,90,40,9,4的设置让代码简短不少,而且也很容易理解。#include #include #include using namespace std;string Integer2Roman(int num) { const int radix[] = {1000原创 2013-12-27 14:20:00 · 1386 阅读 · 0 评论 -
POINT IN CIRCLE 题解
这一题更简单了,求点是否在圆上,直接看离圆心的距离是否等于半径即可#include #include #include using namespace std;int main (int argc, char* argv[]) { ifstream file; string lineBuffer; file.open(argv[1]); while (!file.原创 2013-12-27 12:18:14 · 603 阅读 · 0 评论 -
POKER HANDS题解
这一题我几个月前在UVA上做过,现在找不到源码了,懒得重写一遍,因为这一题不难却非常麻烦,转了邱秋的代码。// Poker Hands (扑克牌型) // PC/UVa IDs: 110202/10315, Popularity: C, Success rate: average Level: 2 // Verdict: Accepted // Submission Dat转载 2013-12-28 09:20:25 · 802 阅读 · 0 评论 -
MINESWEEPER题解
这题也比较简单,只要先把参数从文件读出来,然后做一组判断即可,这题没有看第二遍的价值。#include #include #include using namespace std;string convertStr(string str, int m, int n) { int num; for(int i=0; i<m; i++) { for(int j=0; j<原创 2013-12-28 04:37:35 · 588 阅读 · 0 评论 -
Number Of Ones题解 codeEval
用了个naive的方法,即循环右移统计1出现的个数,本来想如果扣分太多的话就重写,结果只扣了0.1分,那就算了,就这样吧#include #include using namespace std;int main (int argc, char* argv[]) { freopen(argv[1], "r", stdin); int n; while(cin >> n)原创 2013-12-27 10:59:56 · 643 阅读 · 0 评论 -
DISTINCT SUBSEQUENCES 题解
这是我做的第一题hard分类的题,用了dfs,思路很简单,但是码的时候要特别仔细。思路:用dfs搜索,设前一个字符串为str1,后一个为str2如果str1长度小于str2则返回,如果str1与str2相等或者str2长度为0则结果增加1,返回如果str1和str2的第一个字符相等,则str1和str2可以都去掉这个字符然后继续dfs,也可以str1去掉这个字符然后dfs如果str原创 2013-12-27 14:17:07 · 689 阅读 · 0 评论 -
MINIMUM COINS题解 codeEval
思路: 用贪心法,先用面值5的硬币凑,然后是3的 最后是1的#include #include #include using namespace std;int main (int argc, char* argv[]) { ifstream file; string lineBuffer; file.open(argv[1]); while (!file.e原创 2013-12-27 12:14:35 · 613 阅读 · 0 评论 -
LONGEST WORD 解题思路 codeEval
这一题跟PENULTIMATE WORD是一样的,首先拆词出来,然后找到最长的那个单词输出即可#include #include #include #include using namespace std;void split(const string& s, const string& delim, vector &v) { if(s.size() == 0) retu原创 2013-12-27 02:31:10 · 717 阅读 · 0 评论 -
PENULTIMATE WORD解题思路 codeEval
这一题不知道有没有更好的办法,我的思路是先把输入的一行单词放到一个vector中,然后输出倒数第二个。把一行字符串以空格为分界符拆分成一组字符串,我利用了stl中的find_first_of函数,这个函数可以从指定的位置开始搜索指定字符,返回第一个找到的位置。通过find_first_of函数循环搜索到每一个空格,然后把单词拆分出来。#include #include #include原创 2013-12-27 02:27:58 · 768 阅读 · 0 评论 -
OVERLAPPING RECTANGLES题解
两个矩形不重叠的条件无非4种:B在A的上面 B2y > A1y 下面 B1y 左边 B2.x 右边 B1x > A2x除此之外,肯定是重叠的。#include #include #include using namespace std;int main (int ar原创 2013-12-30 07:23:13 · 762 阅读 · 0 评论 -
SWAP CASE题解
这一题太简单了,没什么好说的,不值得做第二遍#include #include #include using namespace std;string switchCase(string lineBuffer) { int size = lineBuffer.size(); for(int i=0; i<size; i++) { if(lineBuffer[i] >=原创 2013-12-29 02:48:57 · 669 阅读 · 0 评论 -
STL的next_permutation与prev_permutation解析
在刷题的时候,next_permutation是非常常用的一个函数,像leetcode的Next Permutation,Permutation Sequence,Permutations,Permutations II都可以用这个函数来偷懒。函数原型:template bool next_permutation( BidirectionalIterator _Firs原创 2014-01-12 12:59:34 · 677 阅读 · 0 评论