Kingsoft pen Exam C ++

Source: Internet
Author: User

1 is the return value different for the overload function?

Certainly not. Function overloading in C ++ must have different parameter lists, regardless of whether the returned values are the same.

2 Stack Overflow

Stack Overflow means that excessive data is written to the data block regardless of the size of the partial data block allocated in the stack, leading to data overflow.

The result overwrites the old stack data.

Http://blog.sina.com.cn/s/blog_44eed07601000de8.html

I think the stack and stack are wrong. In fact, the stack here is the stack structure.

Stack Overflow does not necessarily mean that the entire stack has no space, but actually occupies more than the size of the applied space. In this way, the previous data will be overwritten (the stack grows down, that is, from the high address to the low address)

How can stack overflow be solved?

Avoid out-of-bounds, avoid deep recursive calls, and avoid allocating large objects to the stack.

3

Use the template method to compare the size of two numbers

template<typename T>int compare(T a, T b){    if(a>b) return 1;    else if(a==b) return 0;            else return -1;}

2) full string Arrangement

Recursive Method is relatively simple

void perm(const char *str, int k) {         int i;         if(str[k] == '\0')         {                  cout<<str<<endl;       }         else         {                 for(i = k; i <=strlen(str); i++)                 {   if(str[k] == str[i] && i!=k) continue;                      swap(str[k], str[i]);                         perm(str, k + 1);                         swap(str[k], str[i]);                 }         } } 
3. Design Questions
Each customer has a behavior value v. After a period of time, it becomes V1. If the behavior value is very close, it will be recommended for friends. The value V is between 1 and, the behavior value is close to the absolute value of the behavior values of the two.
My idea is to map these values to the number axis. In this way, the nearest two adjacent points must be smaller.
Based on this idea, there are two solutions
1. Sort the data first. The time complexity is O (nlogn). Then, scan the data again to compare the difference between the two sides of each vertex, and traverse the data again as O (n ), the overall complexity is also nlogn
2 hash
If the behavior value is an integer, hash the table and traverse the hash table.
If it is a floating point number, hashmap can be used to traverse the data.
Therefore, the space complexity is O (n), and the time complexity is O (n)

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.