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

雞蛋編程題

發布時間: 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;
}

熱點內容
路由器密碼是什麼啊 發布:2025-09-19 09:23:25 瀏覽:701
天蠍腳本輔助 發布:2025-09-19 09:22:31 瀏覽:256
官服光遇賬號和密碼在哪裡看 發布:2025-09-19 08:57:15 瀏覽:649
傳奇切割機腳本 發布:2025-09-19 08:35:46 瀏覽:74
博科存儲交換機配置 發布:2025-09-19 08:34:31 瀏覽:138
xp共享win7沒有訪問許可權 發布:2025-09-19 08:29:15 瀏覽:288
cmd運行python程序 發布:2025-09-19 08:16:07 瀏覽:298
如何給你的安卓手機正確充電 發布:2025-09-19 08:15:18 瀏覽:850
vs2010怎麼寫c語言 發布:2025-09-19 07:31:05 瀏覽:882
除了證券外還有哪些投資配置 發布:2025-09-19 07:01:48 瀏覽:89