C++primer 3 string #include #include using namespace std; int main() { //统计标点符号的个数 /* string s("!af,yu,jf!!!"); string::size_type a=0; for(string::size_type i=0;i<=(s.size()-1);++i) if(ispunct(s[i])) a=a+1;
leetcode——Length of Last Word Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string. If the last word does not exist, return 0. Note: A word is
leetcode_remove element Given an array and a value, remove all instances of that value in place and return the new length. The order of elements can be changed. It doesn't matter what you leave beyond the new length. #
如何对待日新月异的软件技术 软件行业的技术更新换代比较快,从事软件相关工作的人要时刻关注新技术的诞生和发展,以求紧跟技术潮流。那么究竟我们应该怎样对待这种现状呢?本文给出了一些见解。 对于日新月异的新技术,你是什么态度? 遇到新技术我会去了解,但不会把很大的精力放在这些技术(如:NoSQL,Node.js,等)。这些技术尚不成熟,只需要跟得住就可以了。技术十年以上可能是一个门槛。有人说
特殊工具与技术---—cplusplus C和C++中如何互相调用(#ifdef __cplusplus) 2008-04-16 17:48:19| 分类: C/C++语言|举报|字号 订阅 本文引用自:http://colding.bokee.com/6416780.html c.h的实现 #ifndef _c_h_ #define _c_h_ #ifdef __cplusplus e
VC++6.0 动态库的创建与调用(非MFC的dll) 非MFC动态库的创建。。。。 lib.cpp#ifndef LIB_H #define LIB_H //声明add为dll的导出函数. extern "C" int _declspec(dllexport)add(int x,int y); #endif /*lib.h*/ #ifndef LIB_H #define LIB_H //声明add为dll的导出函数.
Insertion Sort List ---leetcode---Runtime Error 报错,,可能是因为链表的错误 /** * Definition for singly-linked list. * struct ListNode * { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { publ
ZigZag Conversion ---leetcode /*ZigZag Conversion.cpp*/ #include #include using namespace std; string convert(string s,int nrows) { string last_result; if(nrows==1)//开始没有考虑 { last_result=s; return last_result; } //cout
Best Time to Buy and Sell Stock_Runtime error 1 #include #include #define INF -32760 using namespace std; class Solution { public: int maxProfit(vector &prices) { int *P; int result; P=new int[prices.size()]; for(int i=0;i<prices.siz
分治策略__解决最大连续子数组的问题 // TEST2.cpp : 定义控制台应用程序的入口点。 #include "stdafx.h" #include using namespace std; #define INF -9999999 //求出穿过中点的最大子数组的大小 int MAX_cross_sum(int A[],int low,int mid,int high) { int max_cross; int lef
C++创建动态数组 #include using namespace std; int main() { //创建一维动态数组 int *p1; p1=new int[3]; p1[0]=1;p1[1]=2;p1[2]=3; cout<<*p1<<' '<<*(p1+1)<<' '<<*(p1+2)<<endl; delete []p1; //创建二维数组 int **p2; p2=new in
Sort Colors —1—Leetcode Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue. Here, we will use the integers
递归_简单入门1 #include using namespace std; //递归调用函数1 //F(x)=2*F(x-1)+x*x,F(0)=0; int F(int x) { if(x==0) return 0; else return 2*F(x-1)+x*x; } //递归调用函数2 //输出一个整数。而由于某些原因系统只能输出一个单词每次。 //显示72694,先显示7269再显示4,
广度优先搜索 入门:抓住那头牛 农夫知道一头牛的位置,想要抓住它。农夫和牛都位于数轴上 ,农夫起始位于点N(0 。农夫有两种移动方式: 1、从X移动到X-1或X+1,每次移动花费一分钟 2、从X移动到2*X,每次移动花费一分钟 假设牛没有意识到农夫的行动,站在原地不动。农夫最少要 花多少时间才能抓住牛? /*Catch_The_Cow.cpp*/ #include #include #include
字符串旋转 对于这个问题,咱们换一个角度, 可以这么做: 将一个字符串分成两部分, X 和 Y 两个部分,在字符串上定义反转的操作 X^T,即把 X 的 所有字符反转(如, X="abc",那么 X^T="cba"),那么我们可以得到下面的结论: (X^TY^T)^T=YX。显然我们这就可以转化为字符串的反转的问题了。 不是么?ok,就拿 abcdef 这个例子来说(非常简短的三句,请细看,一看就懂)