【CSummary of language completion function
Under the header file < math.h>, four rounds, five entries, upwards rounding, and down rounding. See the documentation.
Four homes and five entries:double round(double arg);//Returns the nearest integer to arg.
Rounding up:double ceil(double arg);//Returns the smallest integer that is not less than arg.
Down to rounding:double floor(double arg);//Returns the largest integer greater than arg.
Examples:
#include <stdio.h> #include <math.h>//round(),floor(),ceil() int main() { //Rounding printf("round(+2.33) = %+.1f ",round(2.33)); printf("round(+2.49) = %+.1f ",round(2.49)); printf("round(+2.5) = %+.1f ",round(2.5)); printf("round(+2.67) = %+.1f\n",round(2.67)); printf("round(-2.33) = %+.1f ",round(-2.33)); printf("round(-2.49) = %+.1f ",round(-2.49)); printf("round(-2.5) = %+.1f ",round(-2.5)); printf("round(-2.67) = %+.1f\n",round(-2.67)); //Downwards printf("floor(+2.7) = %+.1f ", floor(2.7)); printf("floor(-2.7) = %+.1f ", floor(-2.7)); printf("floor(-0.0) = %+.1f\n", floor(-0.0)); //ceil printf("ceil(+2.4) = %+.1f ", ceil(2.4)); printf("ceil(-2.4) = %+.1f ", ceil(-2.4)); printf("ceil(-0.0) = %+.1f\n", ceil(-0.0)); return 0; }
Output:
round(+2.33) = +2.0 round(+2.49) = +2.0 round(+2.5) = +3.0 round(+2.67) = +3.0 round(-2.33) = -2.0 round(-2.49) = -2.0 round(-2.5) = -3.0 round(-2.67) = -3.0 floor(+2.7) = +2.0 floor(-2.7) = -3.0 floor(-0.0) = -0.0 ceil(+2.4) = +3.0 ceil(-2.4) = -2.0 ceil(-0.0) = -0.0
【I often make low-level mistakes and points for attention.
(1).When you store elements with a vector, you generally first apply for space, such as vector & lt; int & gt; VEC (n), so that you can then enter data without pushing_back(), and subscribe like C. But several times I found it.The data is jammed when reading and reading, and then the program jumps and puzzled. In the end, I found out what a stupid mistake I had made. I spent half a day in this stupid bug. As follows:
//Assuming that the read data n represents the number of nodes, VEC [i] stores the value of the node, and vis [v] indicates whether node V is accessed
//The mistake lies i n statement 1. I habitually give vis space of size n, but the problem is that the value of the node is not said to be 0-n-1, and once the value of VEC [i] is greater than n, statement 1 jumps!!! We must pay attention!!!
int main() { int n; scanf("%d",&n); vector<int> vec(n),vis(n); for(int i=0;i<n;i++){ scanf("%d",&vec[i]); vis[vec[i]]=true;//Statement 1 } return 0; }
So, if you get stuck in entering data or something, see if the space for the vector’s pre-application is not large enough that the subscriber accesses the illegal address!?
(2).According to Grandma’s style, the N nodes given are not necessarily all the nodes of the list, that is, there are interference nodes, so that the list of nodes is actually less than n (although the test cases given can not be seen, but the background test data will set such a pit). Therefore, if necessary, we need toAfter entering data, traverse the list from the beginning of the node, extract the number of valid nodes validCnt, remember not to traverse directly using n. This kind of bug will waste a lot of time unless it is conscious, otherwise it can not be seen. Review: 1052 Linked LisT Sorting, 1133 Splitting A Linked List.