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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

2010有道难题练习赛2

發(fā)布時間:2025/4/14 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 2010有道难题练习赛2 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

?

1?????? A:7無關(guān)的數(shù)

  • 查看
  • 提交
  • 統(tǒng)計
  • 討論

時間限制:

1000ms

內(nèi)存限制:

65536kB

描述

一個正整數(shù),如果它能被7整除,或者它的十進制表示法中某個位數(shù)上的數(shù)字為7,則稱其為與7相關(guān)的數(shù).現(xiàn)求所有小于等于n(n<100)的與7無關(guān)的正整數(shù)的平方和.

輸入

輸入為一行,正整數(shù)n,(n<100)

輸出

輸出小于等于n的與7無關(guān)的正整數(shù)的平方和

樣例輸入

21

樣例輸出

2336??

#include <stdio.h>

?

bool ok(int n)

{

?????? if(n%7==0)

????????????? return true;

?????? for(;n;n/=10)

?????? {

????????????? if(n%10==7)

???????????????????? return true;

?????? }

?

?????? return false;

}

?

int main(int argc, char *argv[])

{

?????? int n;

?????? long long sum=0;

?????? scanf("%d", &n);

?????? for(int i=1; i<=n;i++)

?????? {

????????????? if(!ok(i))

???????????????????? sum += i*i;

?????? }

?

?????? printf("%lld",sum);

?????? return 0;

}

?

2?????? B:unix紀元

  • 查看
  • 提交
  • 統(tǒng)計
  • 討論

時間限制:

1000ms

內(nèi)存限制:

65536kB

描述

在著名的unix系統(tǒng)中,使用了一種簡潔高效的時間表示方法,即:
將1970年1月1日0點作為“unix紀元”的原點,從1970年1月1日開始經(jīng)過的秒數(shù)存儲為一個32位整數(shù)

請編寫一個程序,幫助把一個unix時間輟,轉(zhuǎn)換成形如"YYYY-mm-dd HH:ii:ss"的格式,其中的字母分別代表

YYYY

4 位數(shù)字完整表示的年份

mm

數(shù)字表示的月份,有前導零的 2 位數(shù)字

dd

月份中的第幾天,有前導零的2位數(shù)字

HH

小時,24 小時格式,有前導零

ii

有前導零的分鐘數(shù)

ss

秒數(shù),有前導零

輸入

輸入數(shù)據(jù)有若干行,每行包含一個整數(shù)t,(0<=t<2^31)

輸出

對每一行輸入數(shù)據(jù),輸出一行,為形如“YYYY-mm-dd HH:ii:ss”格式的時間

樣例輸入

10

1234567890

樣例輸出

1970-01-01 00:00:10

2009-02-13 23:31:30

?

#include <stdio.h>

?

#define time_t?? long

#define EPOCH_YR?? 1970

#define FIRSTDAYOF(timp)?? ?? ???(((timp)->tm_wday - (timp)->tm_yday + 420) % 7)

#define FIRSTSUNDAY(timp)?? ???(((timp)->tm_yday - (timp)->tm_wday + 420) % 7)

#define LEAPYEAR(year)?? ?????? ???(!((year) % 4) && (((year) % 100) || !((year) % 400)))

#define SECS_DAY?? (24L * 60L * 60L)

#define TIME_MAX?? ULONG_MAX

#define YEAR0?? 1900

#define YEARSIZE(year)?? ???(LEAPYEAR(year) ? 366 : 365)

?

?struct tm {

?? int tm_sec;?????????????????? /* seconds after the minute [0, 59] */

?? int tm_min;?????????????????? /* minutes after the hour [0, 59] */

?? int tm_hour;????????????????? /* hours since midnight [0, 23] */

?? int tm_mday;????????????????? /* day of the month [1, 31] */

?? int tm_mon;?????????????????? /* months since January [0, 11] */

?? int tm_year;????????????????? /* years since 1900 */

?? int tm_wday;????????????????? /* days since Sunday [0, 6] */

?? int tm_yday;????????????????? /* days since January 1 [0, 365] */

?? int tm_isdst;???????????????? /* Daylight Saving Time flag */

?};

?

?const int _ytab[2][12] = {

???????????????? { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },

???????????????? { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }

???????? };

?

?struct tm

?gmtime( const time_t *timer)

?{

???????? struct tm br_time;

???????? register struct tm *timep = &br_time;

???????? time_t time = *timer;

???????? register unsigned long dayclock, dayno;

???????? int year = EPOCH_YR;

?

???????? dayclock = (unsigned long)time % SECS_DAY;

???????? dayno = (unsigned long)time / SECS_DAY;

?

???????? timep->tm_sec = dayclock % 60;

???????? timep->tm_min = (dayclock % 3600) / 60;

????? ???timep->tm_hour = dayclock / 3600;

???????? timep->tm_wday = (dayno + 4) % 7;?????? /* day 0 was a thursday */

???????? while (dayno >= YEARSIZE(year)) {

???????????????? dayno -= YEARSIZE(year);

???????????????? year++;

???????? }

???????? timep->tm_year = year - YEAR0;

???????? timep->tm_yday = dayno;

???????? timep->tm_mon = 0;

???????? while (dayno >= _ytab[LEAPYEAR(year)][timep->tm_mon]) {

???????????????? dayno -= _ytab[LEAPYEAR(year)][timep->tm_mon];

???????????????? timep->tm_mon++;

???????? }

???????? timep->tm_mday = dayno + 1;

???????? timep->tm_isdst = 0;

?

???????? return br_time;

?}

?

?

int main(int argc, char *argv[])

{

?????? long t;

?????? while(scanf("%d",&t))

?????? {

????????????? time_t tm_t=t;

????????????? struct tm tm_ = gmtime(&tm_t);

????????????? printf("%02d-%02d-%02d %02d:%02d:%02d\n",1900+tm_.tm_year, 1+tm_.tm_mon,tm_.tm_mday,

???????????????????? ?tm_.tm_hour,tm_.tm_min,tm_.tm_sec);

?????? }

?

?????? return 0;

}

?

?

3?????? C:和數(shù)

  • 查看
  • 提交
  • 統(tǒng)計
  • 討論

時間限制:

1000ms

內(nèi)存限制:

65536kB

描述

給定一個整數(shù)序列,判斷其中有多少個數(shù),等于數(shù)列中其他兩個數(shù)的和。 比如,對于數(shù)列1 2 3 4, 這個問題的答案就是2, 因為3 = 2 + 1, 4 = 1 + 3

輸入

第一行是一個整數(shù)T,表示一共有多少組數(shù)據(jù)。 1<= T <= 100
接下來的每組數(shù)據(jù)共兩行,第一行是數(shù)列中數(shù)的個數(shù)n ( 1 <= n <= 100),第二行是由n個整數(shù)組成的數(shù)列。

輸出

對于每組數(shù)據(jù),輸出一個整數(shù)(占一行),就是數(shù)列中等于其他兩個數(shù)之和的數(shù)的個數(shù)。

樣例輸入

241 2 3 453 5 7 9 10

樣例輸出

21

#include <stdio.h>

?

?

int n;

long data[100];

?

int GetNum()

{

?????? int num=0;

?

??????

?????? for(int k=0; k<n; k++)

?????? {

????????????? for(int i=0; i<n;i++)

????????????? {

???????????????????? if(k==i)

??????????????????????????? continue;

?

???????????????????? for(int j=i+1;j<n;j++)

???????????????????? {

??????????????????????????? if(k==j)

?????????????????????????????????? continue;

?

??????????????????????????? if( data[k]==data[i]+data[j] )

?????????????????????????????????? goto Find;

???????????????????? }

????????????? }

????????????? continue;

Find:

????????????? num++;

?????? }

?????? return num;

}

?

int main(int argc, char *argv[])

{

?????? int T;

??????

?????? scanf("%d", &T);

?????? while(T--)

?????? {

????????????? scanf("%d", &n);

????????????? for(int i=0; i<n;i++)

???????????????????? scanf("%d", &data[i]);

????????????? //initSet();

????????????? printf("%d\n",GetNum());

?????? }

?

??????

?????? return 0;

}

轉(zhuǎn)載于:https://www.cnblogs.com/cutepig/archive/2010/05/29/1746937.html

《新程序員》:云原生和全面數(shù)字化實踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀

總結(jié)

以上是生活随笔為你收集整理的2010有道难题练习赛2的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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