# 2015-3-28 Huawei Machine Test Summary

Source: Internet
Author: User

Title: The number of repetitions in an integer sequence is modified to "the value of the number" the number appears in this sequence, the value of the element in the sequence is 1000, and the maximum number in the series is 100.

input : 1,6,3,5,4,6,3,4,4,4

Output:1,6,3,5,4,12,6,8,12,16

The correct procedure is as follows:

#include <iostream>
using namespace Std;
int main ()
{
int i;
int j=0;
int zhen[100]={0};
Char a[100];
Cin.get (a,100);
for (i=0;a[i]!= ' &&a[i]!= ' \ n '; i++)//Get the numbers in the input string
{
if (a[i]>=48)
{
zhen[j]=a[i]-48;
j + +;
}
}
int len=0;
for (int l=0;l<100;l++)//Get the number of inputs
{
if (zhen[l]!=0)
len++;
}
int arr[100]={0};
int count=1;
For the for (int m=0;m<len;m++)//loop operation, the corresponding bit is the number of digits present in the additional array arr ""
{
for (int p=m+1;p<len;p++)
{
if (Zhen[m]==zhen[p])
{
count++;
if (arr[p]==0)
{Arr[p]=count;}
}
}
Count=1;
}
for (int a=0;a<len-1;a++)//Remove last comma output
{
if (arr[a]==0)
cout<<zhen[a]<< ",";
Else
cout<<zhen[a]*arr[a]<< ",";
}
if (arr[len-1]==0)
cout<<zhen[len-1];
Else
cout<<arr[len-1]*zhen[len-1];
System ("pause");
return 0;
}

Some of the problems that arise are:

(1) directly in the original array zhen[] To modify the number, such as the 2nd 4 to modify it to 8, so as to cause the cycle again, if there are 8, it will be changed to 16, thereby making an error;

So, to solve this problem, we need to re-open an array, and then multiply the corresponding bits of two arrays can be obtained;

(2) if (arr[p]==0) This sentence is very important, if there is no such sentence: for example, input 4,4,4,4, then the corresponding arr[] array is 1,2,1,1, so it must be wrong. So first the arr[] array is initialized to 0, in the modified arr "" Bit no changes, this small detail led to not take full points, it is a pity.

2015-3-28 Huawei Machine Test Summary

Related Keywords:

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.