C C++
文章平均质量分 52
学生症
coder
展开
-
c语言中全局变量和局部变量
#include /*在一个源文件中无论写多少个全局变量int a;,它们代表的都是同一个变量。另外,假如在另一个源文件中也有全局变量int a;,那么这两个源文件的所有全局变量int a;也都代表着同一个变量。 */int a;int a;int a;int main (int argc, const char * argv[]){ /* 局部变量多次定义会出现原创 2013-05-31 17:30:20 · 814 阅读 · 0 评论 -
c define 练习
#include#define SUB(x,y) (x-y)#define ACCESS_BEFORE(element,offset,value) *SUB(&element,offset)=valueint main(){ int array[10]={1,2,3,4,5,6,7,8,9,10}; int i; ACCESS_BEFORE(array[5],3,原创 2013-06-11 18:55:35 · 1418 阅读 · 0 评论 -
centos c++ java 学习
参考文章:http://zuoqiang.iteye.com/blog/1157424http://blog.csdn.net/clodfront/article/details/7106426http://www.cnblogs.com/feiyuliu/archive/2012/11/30/2795919.html1、 jdk1.7 配置错误: 找不到或无法加载主类 Hel原创 2012-12-19 14:18:00 · 502 阅读 · 0 评论 -
eclipse c undefined reference to `sqrt'
解决方法:选中项目右键---> properties--->c/c++ build--->settings。。具体参考下图:原创 2013-03-22 13:09:48 · 3023 阅读 · 2 评论 -
把C/C++程序代码中的注释去掉,并返回结果
#include #include #include void remove_commit(char *buf, size_t size) { char *p, *end, c; char *sq_start, *dq_start; char *lc_start, *bc_start; size_t len; p = buf; end =原创 2013-01-20 11:58:20 · 1692 阅读 · 0 评论 -
C语言连接MySql数据库(CodeBlocks)
http://www.cnblogs.com/AndyHoo/archive/2012/07/21/2601883.html补充:1、还需把libmysql.dll放到项目bin\Debug文件夹中,否则可能会出现“无法启动此程序,因为计算机中丢失LIBMYSQL.dll”错误。2、注意#include 一定要放在#include 前面。原创 2013-03-26 15:26:53 · 1796 阅读 · 0 评论 -
eclipse c 只允许在 C99 模式下使用‘for’循环初始化声明
解决方法:选中项目右键---> properties--->c/c++ build--->settings。。具体参考下图:原创 2013-03-22 14:46:53 · 4643 阅读 · 0 评论 -
十进制转二进制 c/c++
1、c++void fun10to2(int n) { if (n < 2) { cout << n; } else { fun10to2(n / 2); cout << n % 2; }}2、cvoid fun_10to2(int n) { if (n < 2) printf("%d", n)原创 2013-01-19 20:39:24 · 808 阅读 · 0 评论 -
c与c++的一些区别
1、c++中支持引用形参void swap(int &x, int &y) {};而c语言中不支持。http://blog.csdn.net/a5987995329/article/details/7455185原创 2013-03-25 16:42:10 · 556 阅读 · 0 评论 -
centos6.3 eclipse c/c++ launch failed no binaries
解决方法:project-->build project/build all即可。原创 2013-03-22 11:53:13 · 1474 阅读 · 0 评论 -
c++ error: 'malloc' was not declared in this scope
IDE:codeblocksc++中使用malloc()时,出现error: 'malloc' was not declared in this scope解决方法:引入stdlib.h#include原创 2013-12-02 17:45:18 · 54192 阅读 · 2 评论 -
c 位域
#includestruct Date1{ unsigned int year; unsigned int month; unsigned int day; unsigned int hour; unsigned int minute; unsigned int second;};struct Date2{ unsigned int year ; unsi原创 2014-03-13 09:36:29 · 676 阅读 · 0 评论 -
c printf 输出格式
#include int main(int argc, char const *argv[]){ int *a[2][3]; printf("%lu\n", sizeof(a)); printf("%d,%4u,%lu\n", 4294967295u, 4294967295u, -1); return 0;}本机为mac os 64bitclang: warning: tr原创 2014-04-01 21:21:40 · 3327 阅读 · 0 评论 -
c 计时
#include #include #include int f(int x){ int s=0; while(x-- >0) s+=f(x); return fmax(s,1);}int main(int argc, char const *argv[]){ struct timeval start, end; gettimeofday( &start, NULL );原创 2014-04-02 14:34:12 · 783 阅读 · 0 评论 -
ThoughtWorks FizzBuzzWhizz
#include #include using namespace std;int main(){ cout<<"pls input 3 numbers a,b,c (0<a,b,c<10 and a!=b!=c):"<<endl; int x1,x2,x3; cin>>x1>>x2>>x3; string str1,str2,str3; ost原创 2014-05-05 16:02:18 · 572 阅读 · 0 评论 -
c 顺序点
#include "stdio.h"int main(int argc, char const *argv[]){ int a1=3; int b1=++a1&printf("%d\n", a1); printf("%d\n", b1); printf("%s\n", "......................"); int a2=5;原创 2014-04-10 11:06:09 · 898 阅读 · 0 评论 -
c sizeof
#include "iostream"using namespace std;int main(int argc, char const *argv[]){ int *a[2][3]; printf("sizeof(*a[0][0]) is %lu\n", sizeof(*a[0][0])); printf("sizeof(a[0][0]) is %lu\n", sizeof(a[0原创 2014-04-13 21:26:55 · 646 阅读 · 0 评论 -
[leetcode] Valid Parentheses
class Solution {public: bool isValid(string s) { if (s.size()%2==1) {//奇数个符号 return false; } //使用栈 stack sc;原创 2014-05-20 10:58:56 · 501 阅读 · 0 评论 -
[leetcode] Word Search
class Solution {public: bool exist(vector > &board, string word) { if (word.size()==0) { return true;//空串返回true } int row=board.size(); int co原创 2014-05-20 00:22:57 · 560 阅读 · 0 评论 -
[leetcode] Sort List
/**Definition for singly-linked list.*/#include using namespace std;struct ListNode{ int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {}};class Solution{public:原创 2014-05-06 14:29:58 · 508 阅读 · 0 评论 -
[leetcode] Merge Two Sorted Lists
Merge Two Sorted Lists原创 2014-05-05 00:09:46 · 527 阅读 · 0 评论 -
[leetcode] Add Two Numbers
#include using namespace std;/** Definition for singly-linked list. */struct ListNode{ int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {}};class Solution{public:原创 2014-05-04 21:48:44 · 632 阅读 · 0 评论 -
[leetcode] Container With Most Water
第一次超时:#include#includeusing namespace std;class Solution {public: int maxArea(vector &height) { int len=height.size(); int tempArea=0; int maxArea=0; for (int i = 0; i <原创 2014-04-29 15:57:14 · 555 阅读 · 0 评论 -
[leetcode] Count and Say
Count and Saysh//// main.cpp// CPPTest//// Created by lyd on 14-5-3.// Copyright (c) 2014年 ___LYD___. All rights reserved.//#include using namespace std;class Solution {public:原创 2014-05-04 00:52:25 · 752 阅读 · 0 评论 -
[leetcode] Permutations
思路:交换+dspclass Solution { vector > res; int length; public: vector > permute(vector &num) { length=num.size();//有length个数 res.clear(); perm(num,0); r原创 2014-06-03 00:07:07 · 591 阅读 · 0 评论 -
sorted Array to BST
sorted Array to BSTstruct BinaryTree{ int value; struct BinaryTree* left; struct BinaryTree* right; BinaryTree(int val){this->value=val;}};BinaryTree* sortedArrayToBST(int arr[原创 2014-07-14 14:18:42 · 788 阅读 · 0 评论 -
[leetcode] Path Sum
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Soluti原创 2014-07-17 20:47:16 · 662 阅读 · 1 评论 -
[leetcode] Path Sum II
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Soluti原创 2014-07-17 21:11:47 · 536 阅读 · 0 评论 -
最上面的扑克牌
#include #include using namespace std;int main(){ queue Qsrc; for (int i=1; i<=13; i++) { Qsrc.push(i); } //cout<<Qsrc.size()<<endl; int cnt=13; int原创 2014-07-19 01:51:45 · 868 阅读 · 0 评论 -
[leetcode] Binary Tree Level Order Traversal II
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Soluti原创 2014-07-20 02:05:22 · 445 阅读 · 0 评论 -
[leetcode] Binary Tree Inorder Traversal
使用递归class Solution {private: vector res;public: vector inorderTraversal(TreeNode *root) { if (root!=NULL) { inorderTraversal(root->left); res.push_back(root原创 2014-07-20 02:36:13 · 473 阅读 · 0 评论 -
[leetcode] Construct Binary Tree from Inorder and Postorder Traversal
Construct Binary Tree from Inorder and Postorder TraversalConstruct Binary Tree from Inorder and Postorder Traversal原创 2014-07-21 01:24:19 · 521 阅读 · 0 评论 -
[leetcode] Binary Tree Zigzag Level Order Traversal
class Solution {private: vector> res;public: vector > zigzagLevelOrder(TreeNode *root) { if (root==NULL) { return res; } queue curQ,nextQ;原创 2014-07-21 00:36:02 · 505 阅读 · 0 评论 -
[leetcode] Binary Tree Postorder Traversal
Binary Tree Postorder Traversal/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NUL原创 2014-07-19 16:46:12 · 480 阅读 · 0 评论 -
[leetcode] Binary Tree Preorder Traversal
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Soluti原创 2014-07-19 13:34:20 · 474 阅读 · 0 评论 -
[leetcode] Binary Tree Level Order Traversal
使用两个队列/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas原创 2014-07-20 01:36:45 · 444 阅读 · 0 评论 -
[leetcode] Convert Sorted List to Binary Search Tree
解法:把链表转换为vectorzclass Solution {public: TreeNode *sortedListToBSTbyIndex(vector &num,int begin,int end){ if (begin>end) { return nullptr; } int mid=be原创 2014-07-21 21:43:05 · 497 阅读 · 0 评论 -
[leetcode] Convert Sorted Array to Binary Search Tree
Convert Sorted Array to Binary Search Treeclass Solution {public: TreeNode *sortedArrayToBSTbyIndex(vector &num,int begin,int end){ if (begin>end) { return null原创 2014-07-21 21:35:26 · 522 阅读 · 0 评论 -
[leetcode] Implement strStr()
Implement strStr()原创 2014-06-02 21:31:37 · 698 阅读 · 0 评论 -
[leetcode] Maximum Subarray
Maximum Subarray原创 2014-06-01 00:47:36 · 659 阅读 · 0 评论