當前位置:首頁 » 編程軟體 » 雞蛋編程題

雞蛋編程題

發布時間: 2022-03-05 06:37:22

Ⅰ c++編程題:雞蛋

#include"stdio.h"
inta[100001];
intmain()
{inti,j,N,n=0;
scanf("%d",&N);
for(i=1;i<=N;i++)
{scanf("%d",&a[i]);
a[i]+=a[i-1];
}
for(i=1;i<=N;i++)
for(j=0;j<i;j++)
if((a[i]-a[j])%7==0)n++;
printf("%d ",n);
return0;
}

Ⅱ C++編程題:雞蛋(大佬請進)

這種題目如果直接用循環是很難搞定的,我給你一個演算法.不過沒有調試,看看你能不能看懂



#include <bits/stdc++.h>
using namespace std;
#define N 100010
int a[N], remainder[N][7];

int main(int argc, char* argv[]) {
int n ;
scanf("%d", &n);
int i, j,r ;
i = 0;
scanf("%d", &a[i]);

for(j=0; j < 7 ; j++) {
remainder[i][j] = 0;
}
remainder[i][a[i]%j] = 0;

for(i++; i< n ; i++) {
scanf("%d", &a[i]);
for(j=0; j < 7 ; j++) {
remainder[i][(j+a[i])%7] = 1+ remainder[i-1][j];
}
}
printf("result:%d", remainder[n][0]);
return 0;
}

熱點內容
ftp登陸指定用戶名和埠號 發布:2025-09-13 01:34:37 瀏覽:655
運行守護怎麼設置安卓 發布:2025-09-13 01:32:37 瀏覽:944
tar解壓了 發布:2025-09-13 01:10:41 瀏覽:115
viplinux 發布:2025-09-13 01:04:40 瀏覽:650
演算法與數據結構面試 發布:2025-09-13 00:59:09 瀏覽:800
phpconfigure 發布:2025-09-13 00:50:17 瀏覽:806
的asp有資料庫 發布:2025-09-13 00:41:41 瀏覽:312
怎麼解壓r 發布:2025-09-13 00:40:50 瀏覽:911
hoco藍牙耳機怎麼配對安卓手機 發布:2025-09-13 00:12:29 瀏覽:859
1c語言 發布:2025-09-13 00:11:42 瀏覽:74