版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、1 1) srm 144 div 2, 250-point problem statement computers tend to store dates and times as single numbers which represent the number of seconds or milliseconds since a particular date. your task in this problem is to write a method whattime, which takes an int, seconds, representing the number of se
2、conds since midnight on some day, and returns a string formatted as :. here, represents the number of complete hours since midnight, represents the number of complete minutes since the last complete hour ended, and represents the number of seconds since the last complete minute ended. each of , , an
3、d should be an integer, with no extra leading 0s. thus, if seconds is 0, you should return 0:0:0, while if seconds is 3661, you should return 1:1:1. definition class: time method: whattime parameters: int returns: string method signature: string whattime(int seconds) constraints seconds will be betw
4、een 0 and 24*60*60 - 1 = 86399, inclusive. examples 0) 0 returns: 0:0:0 1) 3661 returns: 1:1:1 2) 5436 returns: 1:30:36 3) 86399 returns: 23:59:59 (be sure your method is public) source code #include using namespace std; 2 #include class time public: string whattime(int seconds) int h = seconds/3600
5、; int m = seconds/60%60; int s = seconds%60; char str64; sprintf(str, %d:%d:%d,h,m,s); string ret = str; / coutstrendl; return ret; ; void main() time time; / time.whattime(0); / time.whattime(3661); / time.whattime(5436); time.whattime(86399); 2) srm 146 div 2, 250-point problem statement this task
6、 is about the scoring in the first phase of the die-game yahtzee, where five dice are used. the score is determined by the values on the upward die faces after a roll. the player gets to choose a value, and all dice that show the chosen value are considered active. the score is simply the sum of val
7、ues on active dice. say, for instance, that a player ends up with the die faces showing 2, 2, 3, 5 and 4. choosing the value two makes the dice showing 2 active and yields a score of 2 + 2 = 4, while choosing 5 makes the one die showing 5 active, yielding a score of 5. your method will take as input
8、 a int toss, where each element represents the upward face of a die, and return the maximum possible score with these values. definition class:yahtzeescore method:maxpoints parameters:int returns:int 3 method signature:int maxpoints(int toss) (be sure your method is public) constraints toss will con
9、tain exactly 5 elements. each element of toss will be between 1 and 6, inclusive. examples 0) 2, 2, 3, 5, 4 returns: 5 the example from the text. 1) 6, 4, 1, 1, 3 returns: 6 selecting 1 as active yields 1 + 1 = 2, selecting 3 yields 3, selecting 4 yields 4 and selecting 6 yields 6, which is the maxi
10、mum number of points. 2) 5, 3, 5, 3, 3 returns: 10 source code #include #include using namespace std; class yahtzeescore public: int maxpoints(vector toss) int count6; memset(count, 0, sizeof(count); for(int i=0; i5; i+) counttossi-1+=tossi; int max = 0; for(i=0; imax) 4 max=counti; return max; ; vo
11、id main() yahtzeescore* ya = new yahtzeescore; vector v; / test array: 2 2 3 5 4 / 6 4 1 1 3 / 5 3 5 3 3 v.push_back(5); v.push_back(3); v.push_back(5); v.push_back(3); v.push_back(3); int ret = ya-maxpoints(v); coutretendl; 3) srm 147 div 2, 250-point problem statement julius caesar used a system o
12、f cryptography, now known as caesar cipher, which shifted each letter 2 places further through the alphabet (e.g. a shifts to c, r shifts to t, etc.). at the end of the alphabet we wrap around, that is y shifts to a. we can, of course, try shifting by any number. given an encoded text and a number o
13、f places to shift, decode it. for example, topcoder shifted by 2 places will be encoded as vqreqfgt. in other words, if given (quotes for clarity) vqreqfgt and 2 as input, you will return topcoder. see example 0 below. definition class: ccipher method: decode parameters: string, int returns: string
14、method signature: string decode(string ciphertext, int shift) (be sure your method is public) constraints ciphertext has between 0 to 50 characters inclusive each character of ciphertext is an uppercase letter a-z 5 shift is between 0 and 25 inclusive examples 0) vqreqfgt 2 returns: topcoder 1) abcd
15、efghijklmnopqrstuvwxyz 10 returns: qrstuvwxyzabcdefghijklmnop 2) topcoder 0 returns: topcoder 3) zwbglz 25 returns: axchma 4) dbnpcbq 1 returns: camobap 5) lippsasvph 4 returns: helloworld source code #include #include using namespace std; class ccipher public: string decode(string ciphertext, int s
16、hift) string s = ; 6 for(int i=0; i(int)ciphertext.size(); i+) char c = ciphertexti; c = (c-a)-shift+26)%26 + a; s += c; return s; ; int main() ostream_iterator output(cout, ); ccipher cipher; string str = vqreqfgt; string str = cipher.decode(str,2); copy(str.begin(), str.end(), output); coutendl; r
17、eturn 0; 4) srm 148 div2, 250-point problem statement create a class divisordigits containing a method howmany which takes an int number and returns how many digits in number divide evenly into number itself. definition class: divisordigits method: howmany parameters: int returns: int method signatu
18、re: int howmany(int number) (be sure your method is public) notes no number is divisible by 0. constraints number will be between 10000 and 999999999. examples 0) 12345 returns: 3 7 12345 is divisible by 1, 3, and 5. 1) 661232 returns: 2 661232 is divisible by 1 and 2 (doubled). 2) 52527 returns: 0
19、52527 is not divisible by 5, 2, or 7. 3) 730000000 returns: 0 nothing is divisible by 0. in this case, the number is also not divisible by 7 or 3. sourece code #include using namespace std; class divisordigits public: int howmany(int number) int count = 0; int x = number; while(x) int y = x%10; x/=1
20、0; if(0 = y) continue; if(0 = number%y) count+; return count; ; int main(void) divisordigits dd; / int cnt = dd.howmany(12345); / int cnt = dd.howmany(730000000); 8 int cnt = dd.howmany(661232); coutcntendl; return 0; 5) srm 149 div2, 250-point problem statement in documents, it is frequently necess
21、ary to write monetary amounts in a standard format. we have decided to format amounts as follows: the amount must start with $ the amount should have a leading 0 if and only if it is less then 1 dollar. the amount must end with a decimal point and exactly 2 following digits. the digits to the left o
22、f the decimal point must be separated into groups of three by commas (a group of one or two digits may appear on the left). create a class formatamt that contains a method amount that takes two ints, dollars and cents, as inputs and returns the properly formatted string. definition class: formatamt
23、method: amount parameters: int, int returns: string method signature: string amount(int dollars, int cents) (be sure your method is public) notes one dollar is equal to 100 cents. constraints dollars will be between 0 and 2,000,000,000 inclusive cents will be between 0 and 99 inclusive examples 0) 1
24、23456 0 returns: $123,456.00 note that there is no space between the $ and the first digit. 1) 49734321 9 returns: $49,734,321.09 9 2) 0 99 returns: $0.99 note the leading 0. 3) 249 30 returns: $249.30 4) 1000 1 returns: $1,000.01 source code #include #include /#include /#include /#include /#include
25、 /#include /#include /#include /#include /#include #include /#include /#include /#include /#include /#include using namespace std; class formatamt public: string amount(int, int); ; string formatamt:amount(int dollars, int cents) 10 string str = ; int n = 0; int a100; while(dollars 0) an+ = dollars%
26、10; dollars /= 10; int count = 0; for(int i=0; i 0) an+ = cents % 10; cents /= 10; for(i=1; i=0; i-) str += char(ai + 48); return str; int main(void) formatamt amt; coutamt.amount(123456,0)endl; coutamt.amount(49734321,9)endl; coutamt.amount(0,99)endl; coutamt.amount(100,1)endl; return 0; 11 6) srm
27、150 div 2, 250-point problem statement when a widget breaks, it is sent to the widget repair shop, which is capable of repairing at most numperday widgets per day. given a record of the number of widgets that arrive at the shop each morning, your task is to determine how many days the shop must oper
28、ate to repair all the widgets, not counting any days the shop spends entirely idle. for example, suppose the shop is capable of repairing at most 8 widgets per day, and over a stretch of 5 days, it receives 10, 0, 0, 4, and 20 widgets, respectively. the shop would operate on days 1 and 2, sit idle o
29、n day 3, and operate again on days 4 through 7. in total, the shop would operate for 6 days to repair all the widgets. create a class widgetrepairs containing a method days that takes a sequence of arrival counts arrivals (of type vector ) and an int numperday, and calculates the number of days of operation. definition class: widgetrepairs method: days parameters: vector , int returns: int method signature: int days(vector arrivals, int numperday) (be sure your method is public) constraints arrivals contains betwee
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 北師大版(2019)必修第三冊(cè) Unit7Art Lesson 2 Beijing Opera 第二課時(shí)教學(xué)設(shè)計(jì)
- 統(tǒng)編版語文六年級(jí)上冊(cè)第七單元主題閱讀(含答案)
- 《 沉浸式藝術(shù)展及其審美特征研究》范文
- 《 采場壓力拱演化特征及失穩(wěn)機(jī)理分析》范文
- 地理第旅游開發(fā)與保護(hù)旅游開發(fā)中的環(huán)境保護(hù)
- 人教版九年級(jí)下冊(cè)化學(xué)第八單元同步測(cè)試卷含答案
- 第4課《曹沖稱象》閱讀理解題(含答案)
- 《 基于GA-PIDNN的板形模式識(shí)別與智能控制》范文
- Unit 5 Animal friends (學(xué)案教學(xué)設(shè)計(jì))2024-2025學(xué)年 冀教版七年級(jí)英語上冊(cè)
- 《 內(nèi)蒙古慈善組織公信力建設(shè)研究》范文
- 工地門頭招牌工程施工承包合同
- 中醫(yī)學(xué)術(shù)論文參考文獻(xiàn)
- 形勢(shì)與政策(“四個(gè)正確認(rèn)識(shí)”專題)智慧樹知到答案章節(jié)測(cè)試2023年棗莊學(xué)院
- 純陽祖師入火鏡
- 抗菌藥物試題及答案
- 環(huán)保專項(xiàng)資金申請(qǐng)報(bào)告
- 《念奴嬌 赤壁懷古》《永遇樂 京口北固亭懷古》《聲聲慢》群文閱讀 課件 【備課精講精研】 統(tǒng)編版高中語文必修上冊(cè)
- 中醫(yī)內(nèi)科學(xué)-咳嗽演示教學(xué)課件
- 產(chǎn)品開發(fā)設(shè)計(jì)課件
- (病退復(fù)核表)無錫市非因工傷殘或因病喪失勞動(dòng)能力復(fù)核鑒定申請(qǐng)表
- 上海市松江區(qū)2022屆中考二模物理試卷(含答案)
評(píng)論
0/150
提交評(píng)論