华为机考模拟题

 一、字符串平均重量

华为机考模拟题_第1张图片

 


// we have defined the necessary header files here for this problem.
// If additional header files are needed in your program, please import here.

int main()
{
    // please define the C++ input here. For example: int a,b; cin>>a>>b;;
    // please finish the function body here.
    // please define the C++ output here. For example:cout<<____<>str){
        strNum++;
        total+=str.size();
    }
    printf("%.2f",total/strNum);
    return 0;
}

二、solo习惯

华为机考模拟题_第2张图片


// we have defined the necessary header files here for this problem.
// If additional header files are needed in your program, please import here.

int main()
{
    // please define the C++ input here. For example: int a,b; cin>>a>>b;;
    // please finish the function body here.
    // please define the C++ output here. For example:cout<<____<='A'&&str[i]<='Z'){
            str[i]=str[i]+('a'-'A'); 
        }
    }
    cout<

三、计算字符串重新排列数华为机考模拟题_第3张图片

 

 完成67%

#include
#include
#include
// we have defined the necessary header files here FOR this problem.
// IF additional header files are needed IN your program, please IMPORT here.
int main()
{
    // please define the C input here. FOR EXAMPLE: int n; scanf("%d",&n);
    // please finish the FUNCTION body here.
    // please define the C output here. FOR EXAMPLE: printf("%d",a);
    char num[9];
    cin>>num;
    int n = strlen(num);
    int result=0;
    sort(num,num+n);
    do
    {
     //for(int i=0;i

 完成97%

//#include 
//#include 
// we have defined the necessary header files here for this problem.
// If additional header files are needed in your program, please import here.
#include
using namespace std;
void AllPermutation(string perm, int from, int to);
int num=0;
set sets;
int main()
{
    // please define the C++ input here. For example: int a,b; cin>>a>>b;;
    // please finish the function body here.
    // please define the C++ output here. For example:cout<<____< to)
        return;
            
    if(from == to)     //打印当前排列 
    {	
        static int count = 1;    //局部静态变量,用来统计全排列的个数  
        num=count;
        count++;
        sets.insert(perm);
		//cout << count++ << ":" << perm;
        //cout << endl;
    }
    if(from < to)     //用递归实现全排列 
    {
        for(int j = from; j <= to; j++)    //第j个字符分别与它后面的字符交换就能得到新的排列
        {
                swap(perm[j], perm[from]);
            //cout<<0;
            AllPermutation(perm, from + 1, to);
            //cout<<1;
            swap(perm[j], perm[from]);
            //cout<<2;
            
        }
    }
}

100% 


// we have defined the necessary header files here for this problem.
// If additional header files are needed in your program, please import here.
#include
#include

using namespace std;

int main()
{
    // please define the C++ input here. For example: int a,b; cin>>a>>b;;
    // please finish the function body here.
    // please define the C++ output here. For example:cout<<____<

你可能感兴趣的:(C++,C++)