Cygwin compilation win7cocos2d-x Android project reports "cc1plus.exe: Fatal error: JNI/hellocpp/Main. cpp: Permission denied" error,
This is the permission problem, run cygwin as administrator under win7, enter the project directory, such as CD/cygdrive/D/Alex/tools/Android/cocos2d-x-2.1.4/myfistcoco/proj. Android,
Switch to the Windows console as a management Meta and specify the project directory,
Next, modify the permissions of the
Topic:Given a complete binary tree, count the number of nodes.Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, was completely filled, and all nodes As far left as possible. It can has between 1 and 2h nodes inclusive at the last level H.Code:/** Definition for a binary tree node. * struct TreeNode {* int val; * TreeNode *left; * TreeNode *right; * TreeNode (int x): Val (x), left (null), right (NULL) {} *}; */classSolution { Publ
There's a big discussion about this on StackOverflow .https://stackoverflow.com/questions/2924058/confused-about-stdruntime-error-vs-stdlogic-error/6476858#6476858? Newreg=7f576920c83943698339b83d8ca1f1bdc++0x standard says (clause 19.2): That's how it's described.1) in the error model reflected in these classes (i.e. the exception types), errors is divided into the broad categories: Logic errors and runtime errors.2) The distinguishing characteristic of logic errors is, they is due to errors in
"destructor called"Endl;}Private: //A (const a a) {cout intx;}; A get_a () {A A (5); returnA;}intMain () {cout"-----1-----"Endl; A A=1;//1coutEndl; cout"-----2-----"Endl; A b= Get_a ();//2coutEndl; cout"-----3-----"Endl; b= A;//3coutEndl; cout"-----4-----"Endl; A C= A (2);//4coutEndl; cout"-----5-----"Endl; b=3;//5coutEndl; cout"-----6-----"Endl; A D= b;//6coutEndl; cout"-----7-----"Endl; A e (b); //7coutEndl; return 0;}Run resultsFor the 1th and 4th, why is there no copy constructor
#include int s1[1005000],s2[1005000];If main is an array of global variables defined in the array's outer function, initialize array 0 by itself;To define an array in main, remember to initializeint main (){int n,l,r;int a,b,c,d,g=1;The method of prime number playing tableS1[0]=s1[1]=1;for (a=0;a{if (S1[a])Continuefor (B=a+a;bs1[b]++;}D=0;for (a=0;a{B=a;c=0;while (b){c+=b%10;b/=10;}if (s1[c]==0s1[a]==0)D++;//D is the number of US primesS2[a]=d;//s2 "A" is the number of us primes from 0 to a}scan
DescriptionGiven a polynomial, output the result of its simplification.InputA string that contains only the polynomial of the letter x, without parentheses and fractions, with no extra spaces.OutputA string that, after simplifying the polynomial, outputs the items in the order of the times from large to small.Input SampleX^3+3*x^4-2*x^3+1-xOutput Sample3*x^4-x^3-x+1HintEach coefficient The annoying analog code is as follows:#include Yzoi Easy Round 2_ Simplification (Simplify.c/
title :Given a singly linked list l: l0→l1→ ... →ln-1→lN,Reorder it to: l0→ln→l1→ln-1→l2→L n-2→ ...You must does this in-place without altering the nodes ' values.For example,Given {1,2,3,4} , reorder it to {1,4,2,3} .Code :/** Definition for singly-linked list. * struct ListNode {* int val; * ListNode *next; * ListNode (int x) : Val (x), Next (NULL) {}}; */classSolution { Public: voidReorderlist (ListNode *head) { if(!head)return; ListNode Dummy (-1); Dummy.next=Head; ListNode*P1 = d
title :Given a list, rotate the list to the right by K -places, where K is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2 ,Return 4->5->1->2->3->NULL .Code :/** Definition for singly-linked list. * struct ListNode {* int val; * ListNode *next; * ListNode (int x) : Val (x), Next (NULL) {}}; */classSolution { Public: ListNode* Rotateright (listnode* head,intk) {if(!head | |! (Head->next))returnHead; ListNode*p =Head; intLen =1; for(;p->next;++len,p=p->next) {} ListNode*end =p; K= k%
title :You are given a n x n 2D matrix representing an image.Rotate the image by degrees (clockwise).Follow up:Could do this in-place?Code :classSolution { Public: voidRotate (vectorint> > matrix) { ConstUnsignedintLen =matrix.size (); if(Len 2)return; for(introw =0; Row row) { for(intCol =0; Col 1-row; ++Col) {Std::swap (Matrix[row][col], Matrix[len-1-col][len-1-row]); } } for(introw =0; Row 2; ++row) { for(intCol =0; Col Col
)]++; //substring occur more than times in words if(Found[s.substr (I,len_w)]>ori[s.substr (i,len_w)]) {found.clear (); Match_num=0; Begin++; I=begin; Continue; } I= i+Len_w; Match_num++; //cout //match all substrings in words and push back a starting indices if(match_num==words.size ()) {Ret.push_back (i-end); Found.clear (); Begin++; I=begin; Match_num=0; } } //Not match
In CPP, a static variable in a class does not belong to any one instance.Below, the two methods are used to prove the situation.1.classstudent{Private: stringname; intAge ; intheight; Static intMoney ; Public: Student (stringInputName,intinputage): Name (InputName), age (Inputage) {}voiddisplaystudent () {coutEndl; coutEndl; }};intMain () {FStream fs ("Out.dat"Ios:: out|ios::binary); Student STU1 ("He", -); Fs.write (reinterpret_castChar*> (AMP;STU
Topic:Given a binary tree, return the bottom-up level order traversal of its nodes ' values. (ie, from the left-to-right, the level by level from the leaf to root).For example:Given binary Tree {3,9,20,#,#,15,7} , 3 / 9 / 7Return its bottom-up level order traversal as:[ [15,7], [9,20], [3]]Code:/** Definition for a binary tree node. * struct TreeNode {* int val; * TreeNode *left; * TreeNode *right ; * TreeNode (int x): Val (x), left (null), right (NULL) {} *}; */classSolution { Pu
"Endl; A -V.erase (V.end ()-5, V.end ()); -cout "After erase:"Endl; thecout "size of v is"Endl; -cout "capacity of V is"Endl; - -vectorint>(v). Swap (v); +cout "After swap (shrink to fit):"Endl; -cout "size of v is"Endl; +cout "capacity of V is"Endl; A atvectorint>(). Swap (v); -cout "After swap (clear):"Endl; -cout "size of v is"Endl; -cout "capacity of V is"Endl; - - return 0; in}The output is:Initial:size of v is Tencapacity of V is TenAfter erase:size of v is 5capacity of V i
Topic:Write a function to find the longest common prefix string amongst an array of strings.Code:classSolution { Public: stringLongestcommonprefix (vectorstring>STRs) { if(strs.size () = =0)return ""; STD::stringTmp_str = strs[0]; for(size_t i =1; I i) {size_t J=0; for(; J j)if(Tmp_str[j]!=strs[i][j]) Break; Tmp_str= Tmp_str.substr (0, J); } returnTmp_str; }};TipsSpace complexity O (N1), Time complexity O (n1+n2 ...)Each string string in the STRs is compared sequential
=""; } Else{Tmp_part+=Path[i]; } } if(Ret.size () >1 ret[ret.size ()-1]=="/") Ret.erase (Ret.end ()-1); for(size_t i =0; I Ret[i]; returnresult; }};TipsThe main idea is the data structure of stack stacks.1. Use "/" as the interval judgment symbol2. Tmp_part is a string part between two "/" (Note that the input path may not end with "/", the workaround is to manually fill in one after the path)3. If the Tmp_part is "..", two elements are out of the stack (pro
is two:A. What was the previous character (that is, Prechar in the code)B. Dot,sign,exp,digit, have you ever seenThe advantage of this code logic is that if you look for two core judgment logic and tinker with the two core logic, you can constantly brush the test case until AC.If there are similar problems in the future, the condition conditions are very many, but the input conditions are relatively fixed, and they need to be judged according to the serialized input criteria.You can set a numbe
thatPart_a = Ia==a.rend ()? 0: *ia-' 0 '; (int)Result.insert (Result.begin (), sum%2+ ' 0 '); (char)The same is the addition and subtraction between int and char, why is the returned type different?The guess should be this: the arithmetic is converted to ASCII code of the value of the addition and subtraction, and finally if the requirement is an int to maintain the int type, need to be char to convert to char type.C + + Primer Plus (Fourth edition) 45~47 explains this conversion.' 0 ' can be u
title :Suppose a sorted array is rotated on some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2 ).You is given a target value to search. If found in the array is return its index, otherwise return-1.Assume no duplicate exists in the array.Code :classSolution { Public: intSearchintA[],intNinttarget) { intBegin =0; intEnd = N1; while(Begin! =end) { if(begin+1==end) { if(A[begin]==target)returnbegin; if(A[end]==target)returnend;
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.