统计数组某个元素的数量

本文介绍了一个C++函数ufusr,它对目标数组进行排序并查找重复元素及其出现次数,使用了标准库中的算法和UF系列函数。
摘要由CSDN通过智能技术生成

#include <uf.h>
#include <uf_ui.h>
#include<stdio.h>
#include <algorithm>

using namespace std;

void ufusr(char*parm, int*returnCode, int rlen)
{
    UF_initialize();

    double a[30] = { 1,5,9,8,4,5,5,3,4,7,5,8,55,44,7,9,11,33,77,2,22,44,77,66,77,3,4,7,88,22 };//目标数组

    sort(a, a + 30);//从小到大排序

    int i, j;

    int num = 0;

    int flag = 0;  //定义一个标记,初始为0

    for (i = 0; i < 30; i++)//遍历全部数组成员
    {

        for (j = 0; j < 30; j++)
        {


            if (a[i] == a[j])//假如一个目标A和另一个成员B相等
            {

                if (i <= j)//A的位置不在B的位置之后
                {
                    num++;//统计数量

                    flag = 1;//把A标记为“1”
                }

                else//其他情况
                {
                    flag = 0;//标记为0;
                    break;//打断循环,重新遍历
                }

            }

        }

        if (flag == 1)//标记为1的对象
        {


            char s[256];

            char b[256];

            sprintf(s, "%.f", a[i]);

            sprintf(b, "%d", num);

            UF_UI_open_listing_window();

            UF_UI_write_listing_window(s);

            UF_UI_write_listing_window("  出现次数   ");

            UF_UI_write_listing_window(b);

            UF_UI_write_listing_window("\n");


            num = 0;//

            
        }
    }

    UF_terminate();
}
int ufusr_ask_unload(void)
{
    return (UF_UNLOAD_IMMEDIATELY);
}

  • 8
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值