Huawei machine Test--speed

Source: Internet
Author: User

Source:
Describe:

A car with a fixed speed, the driver sees a reading on the odometer (6-digit odometer) at 10 o'clock in the morning

is a symmetric number (that is, the number reads from left-to-right and right-to-left reading is exactly the same, for example, 95859 km).

A new symmetry number appeared on the odometer two hours later. Q. What is the speed (km/h) of the car?

Interface description

Prototype:

int calcspeedofcar (int icurrentmileage, int * picarspeed);

Input parameters:

int pccurrentmileage: Current number of miles (for symmetric number) (Pccurrentmileage ≤ 999999)

Output parameters:

int * picarspeed: car Speed

return value:

0: Car speed calculation success

1: Car speed calculation fails, the next symmetric number cannot be found within the range of the odometer

Knowledge point:

Engineering environment use vs2005

 

Software training camp
Practice Stage: Primary

The topic is simple, pay attention to a few key points, odd digits or even digits, whether the integer is full 9, whether the middle symmetry position is 9, and this symmetric number is required to be an integer less than seven digits, to do boundary detection ~


#include <iostream>using namespace std; /* Function: Calculates speed prototype based on mileage: int calcspeedofcar (int icurrentmileage, int * picarspeed), input parameter: int pccurrentmileage: Current mileage (for symmetric number) (p ccurrentmileage≤999999) return value: Car speed (km/h) */int calcspeedofcar (int icurrentmileage, int * picarspeed) {/* Implement function here */cha R Tmp[7],tmp2[8];itoa (icurrentmileage,tmp,10), int i,slen=strlen (TMP), if (slen>6) return 1;if (slen%2)//Odd {if (tmp[ slen/2]< ' 9 ') {tmp[slen/2]++;*picarspeed= (atoi (TMP)-icurrentmileage)/2;return 0;} else//tmp[slen/2]== ' 9 ' {itoa (icurrentmileage+1,tmp2,10); if (strlen (TMP2) >slen) {if (slen>5) return 1;* Picarspeed=1;return 0;} I=slen/2;while (tmp[i]== ' 9 ') {tmp[i]= ' 0 '; i--;} Tmp[i]++;for (i=0;i<slen/2;i++) tmp[slen-i-1]=tmp[i];*picarspeed= (atoi (TMP)-icurrentmileage)/2;return 0;}} else//even {itoa (icurrentmileage+1,tmp2,10), if (strlen (TMP2) >slen) {if (slen>5) return 1;*picarspeed=1;return 0;} I=slen/2-1;while (tmp[i]== ' 9 ') {tmp[i]= ' 0 '; i--;} Tmp[i]++;for (i=0;i<slen/2;i++) tmp[slen-1-i]=tmp[i];*picarspeed= (atoi (TMP)-icurrentmileage)/2;return 0;} return 0;} int main () {int speed; Calcspeedofcar (1991,&speed); Cout<<speed<<endl;return 0;}



Huawei machine Test--speed

Related Article

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.