bool ReadSrt(const std::string& filename, std::vector<Subtitle>& subtitles) { std::ifstream srt(filename); if (!srt) return false; for (std::string line; getline(srt, line);) { unsigned int h, m, s, f, h2, m2, s2, f2; if (sscanf(line.c_str(), "%u:%u:%u,%u --> %u:%u:%u,%u", &h, &m, &s, &f, &h2, &m2, &s2, &f2) != 8) { continue; } auto start = (int) timecode_to_milliseconds(h, m, s, f); auto stop = (int) timecode_to_milliseconds(h2, m2, s2 ,f2); std::vector<std::string> text_lines; while (getline(srt, line)) { if (line.empty()) break; text_lines.push_back(std::move(line)); } if (!subtitles.empty() && subtitles.back().stop > stop) continue; subtitles.emplace_back(start, stop, std::move(text_lines)); } return true; }
int InversePairs(vector<int> data) { //暴力求解,复杂度太大,无法通过。 /* int ret=0; for(int i=0;i<data.size()-1;i++){ for(int j=i+1;j<data.size();j++){ if(data[i] > data[j]) ++ret; } } return ret;*/ //分治统计法: /* 7 5 6 4 / \ a、将问题拆分为 7 5 | 6 4 / \ 7 | 5| 6 | 4 b、当问题规模为一时将问题合并,排序,统计逆序对 \ / \ / 5 7 | 4 6 比对,比较7和6,因为7>6,且4 6是排好序的,所以逆序对为2(4和6),继续考察5和6 \ / 4 5 6 7 */ vector<int> srt(data.size()); return solve(data,srt,0,data.size()-1); }
void closchan(short cnum) { BOOLEAN aflag=FALSE; short mcto=0; char temps[2048]; if(chan<0){ form_alert(1,"[1][You're not in|a channel!][ooops!]"); return; } while(mcto<30 && !aflag){ if(cnum!=mcto && chan[mcto].win==chan[cnum].win){wn[chan[cnum].win].chan=mcto;aflag=TRUE;} mcto++; } if(!aflag){ wn[chan[cnum].win].chan=-1; dowindinfo(chan[cnum].win); cycchan(FORWARDS); } if(chan[cnum].stat==2){ sprintf(temps,":%s PART %s\r",cn[wn[chan[cnum].win].cnn].nick,chan[cnum].name); srt(temps,cn[wn[chan[cnum].win].cnn].cn); } if(chan[cnum].stat>2)closedccchat(cnum); chan[cnum].stat=0; if(aflag)dowindinfo(chan[cnum].win); chan[cnum].win=-1; return; }
TEST(PaydayTransactionForCommisionedEmployeeTest, PayrollTest) { ((DatabaseProxy *)getInstance())->ClearEmployees(); int empid = 101; Date date(2012, 10, 10); double amount = 1000.00; AddCommisionEmployee ace(empid, "name02", "Home6", 1000.00, 0.5); ace.Execute(); SalesReceiptTransaction srt(empid, date, amount); srt.Execute(); Employee *e = ((DatabaseProxy *)getInstance())->GetEmployee(empid); PaymentClassification* pc = e->GetPaymentClassification(); EXPECT_TRUE(pc != 0); CommisionClassification* cc = dynamic_cast<CommisionClassification*>(pc); EXPECT_TRUE(cc != 0); SalesReceipt receipt(cc->GetSalesReceipt(date)); EXPECT_TRUE(receipt.GetAmount() == amount); Date paydate(2011, 2, 14); PaydayTransaction pt(paydate); pt.Execute(); PayCheck *check = pt.GetPayCheck(empid); EXPECT_TRUE(check->GetName() == "name02"); EXPECT_EQ(check->GetGrossPay(), 1500.00); EXPECT_EQ(check->GetDeductions(), 0.0); EXPECT_EQ(check->GetNetPay(), 1500.00); }
int main(int argc, char *argv[]) { srand(time(NULL)); int arr[100] = { 3, 1, 4, 7, 10, 11 }; int n = 6; if (argc == 1) { printf("Invalid num args\nCommand line input was expected\nRunning with default number\n"); putchar('\n'); int i; for(i=0; i<n; ++i) printf("%d ", arr[i]); putchar('\n'); } else if (argc == 2) { n = atoi(argv[1]); printf("In : "); gen(arr, n); putchar('\n');; } else { n = atoi(argv[1]); int i; printf("In : "); for(i=0; i<n; ++i) printf("%d ", arr[i] = atoi(argv[i + 2])); putchar('\n');; } init(); int x = srt(arr, n); if (x == -INF) { printf("No repetitions\n"); } else { printf("Repition :"); printf("%d ", x); putchar('\n'); } printf("Topsort: "); topsort(); putchar('\n'); return 0; }
int initiatedccchat(char *usr){ short blah; uint32 cip; char temps2[2048]; blah=findfreedccchat(); if(blah==-1){form_alert(1,"[1][No free chats :(][Oh dear]");return 0;} chan[blah].cn=TCP_open(0L,0,0,2048); cb=CNgetinfo(cn[wn[cwin].cnn].cn); cip=stik_cfg->client_ip; if(cip==0 || cip==0x7F000001)cip=cb->lhost; cb = CNgetinfo(chan[blah].cn); sprintf(temps2,":%s PRIVMSG %s :\001DCC CHAT chat %lu %u\001\r",cn[wn[cwin].cnn].nick,usr,cip,cb->lport); srt(temps2,cn[wn[cwin].cnn].cn); chan[blah].stat=SAWAIT; strcpy(chan[blah].name,usr); chan[blah].win=cwin; return 1; }
TEST(SalesReceiptTransactionTest, PayrollTest) { int empid = 6; Date date(2012, 10, 10); double amount = 1000.00; AddCommisionEmployee ace(empid, "Test6", "Home6", 1000.00, 0.5); ace.Execute(); SalesReceiptTransaction srt(6, date, amount); srt.Execute(); Employee *e = ((DatabaseProxy *)getInstance())->GetEmployee(empid); PaymentClassification* pc = e->GetPaymentClassification(); EXPECT_TRUE(pc != 0); CommisionClassification* cc = dynamic_cast<CommisionClassification*>(pc); EXPECT_TRUE(cc != 0); SalesReceipt receipt(cc->GetSalesReceipt(date)); EXPECT_TRUE(receipt.GetAmount() == amount); }