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

雞蛋編程題

發布時間: 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-07-05 16:10:30 瀏覽:514
微博資料庫設計 發布:2025-07-05 15:30:55 瀏覽:18
linux485 發布:2025-07-05 14:38:28 瀏覽:298
php用的軟體 發布:2025-07-05 14:06:22 瀏覽:747
沒有許可權訪問計算機 發布:2025-07-05 13:29:11 瀏覽:421
javaweb開發教程視頻教程 發布:2025-07-05 13:24:41 瀏覽:679
康師傅控流腳本破解 發布:2025-07-05 13:17:27 瀏覽:229
java的開發流程 發布:2025-07-05 12:45:11 瀏覽:675
怎麼看內存卡配置 發布:2025-07-05 12:29:19 瀏覽:274
訪問學者英文個人簡歷 發布:2025-07-05 12:29:17 瀏覽:824