日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

c语言打印数组元素_C程序打印元素差为0或1的子集数

發(fā)布時(shí)間:2023/12/1 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c语言打印数组元素_C程序打印元素差为0或1的子集数 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

c語(yǔ)言打印數(shù)組元素

Given an array of integers, find and print the maximum number of integers you can select from the array such that the absolute difference between any two of the chosen integers is less than or equal to 1.

給定一個(gè)整數(shù)數(shù)組,查找并打印可以從數(shù)組中選擇的最大整數(shù)數(shù),以使任意兩個(gè)選定整數(shù)之間的絕對(duì)差小于或等于1。

For example, if your array is a = [1,1,2,2,4,4,5,5,5]

例如,如果您的數(shù)組是a = [1,1,2,2,4,4,5,5,5]

You can create two subarrays meeting the criterion: [1,1,2,2] and [4,4,5,5,5]. The maximum length subarray has 5 elements.

您可以創(chuàng)建兩個(gè)滿足條件的子數(shù)組:[1,1,2,2]和[4,4,5,5,5] 。 最大長(zhǎng)度子數(shù)組包含5個(gè)元素。

Input format:

輸入格式:

The first line contains a single integer a, the size of the array b.
The second line contains a space-separated integers b[i].

第一行包含一個(gè)整數(shù)a ,即數(shù)組b的大小。
第二行包含以空格分隔的整數(shù)b [i] 。

Output format:

輸出格式:

A single integer denoting the maximum number of integers you can choose from the array such that the absolute difference between any two of the chosen integers is <=1.

表示您可以從數(shù)組中選擇的最大整數(shù)數(shù)的單個(gè)整數(shù),以使任意兩個(gè)所選整數(shù)之間的絕對(duì)差為<= 1 。

Constraint:

約束:

2<=a<=100

2 <= a <= 100

Example:

例:

Input:64 6 5 3 3 1Output:3

Description:

描述:

We choose the following multiset of integers from the array:{4,3,3}. Each pair in the multiset has an absolute difference <=1(i.e., |4-3|=1 and |3-3|=0 ), So we print the number of chosen integers, 3 - as our answer.

我們從數(shù)組中選擇以下整數(shù)整數(shù)集:{4,3,3} 。 多重集中的每一對(duì)都有一個(gè)絕對(duì)差異<= 1(即| 4-3 | = 1和| 3-3 | = 0) ,因此我們打印選擇的整數(shù)3的數(shù)目作為答案。

Solution:

解:

#include <stdio.h> int main() {//a is the length of array and b is the name of array.int a, t, i, j, count, k;count = 0;printf("Enter the size of the array: ");scanf("%d", &a);int b[a], d[101];printf("Enter array elements: ");for (i = 0; i < a; i++) {scanf("%d", &b[i]);}for (i = 0; i <= 100; i++) {for (j = 0; j < a; j++) {if (i == b[j]) {count = count + 1;}}d[i] = count;count = 0;}t = d[0] + d[1];for (i = 0; i < 100; i++) {k = d[i] + d[i + 1];if (k > t) {t = k;}}printf("Number of subset: %d", t);return 0; }

Output

輸出量

Enter the size of the array: 9 Enter array elements: 1 1 2 2 4 4 5 5 5 Number of subset: 5

翻譯自: https://www.includehelp.com/c-programs/print-the-number-of-subset-whose-elements-have-difference-0-or-1.aspx

c語(yǔ)言打印數(shù)組元素

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)

總結(jié)

以上是生活随笔為你收集整理的c语言打印数组元素_C程序打印元素差为0或1的子集数的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。