void main() {int a[4][4]; cout<<"please input the int"<<endl; for(int x=0;x<4;x++) for(int y=0;y<4;y++) cin>>a[x][y]; int b=number1(a); int c=number2(a); cout<<"第一条对角线的和为:"<<" "<<b<<endl; cout<<"第二条对角线的和为:"<<" "<<c<<endl; }
DEF_TEMP void PE_TEST::testCalculatePeriodicElements() { NSDigitSet digits; iVector d(2, 0); digits.push_back(d); d[0] = 1; digits.push_back(d); d[0] = -1; d[1] = 0; digits.push_back(d); iMatrix base(2,2); base(0,0) = 1; base(0,1)= -2; base(1,0) = 1; base(1,1) = 1; NumSys ns(base, digits); iVector number(2, 0); iVector number2(2, 0); number[0] = 1; number[1] = 0; number2[0] = 0; number2[1] = 1; AbstractCalc* pcalc = new PE_CALC(&ns); try { typename PE_CALC::Parameter params(number, number2, 0, 1, 1, 10, 10); NSDigitSet ret = pcalc->calculatePeriodicElements(params); assertNotEquale(ret.size(), 1); }catch(Exceptions::RuntimeException& ex) { std::cout<<ex<<std::endl; } delete pcalc; }
void peano::applications::latticeboltzmann::blocklatticeboltzmann::configurations::PlaneBoundaryConfiguration:: parseInterval(std::string interval){ for (int d = 0; d < DIMENSIONS; d++){ std::string number1(""); std::string number2(""); tarch::irr::io::IrrXMLReader* getNumbers = tarch::irr::io::createIrrXMLReaderFromString(""); size_t closedPos1 = interval.find("["); size_t openPos1 = interval.find("("); size_t closedPos2 = interval.find("]"); size_t openPos2 = interval.find(")"); size_t semicolonPos = interval.find(";"); size_t first = 0; size_t last = 0; // determine left bracket position if ( (closedPos1 == std::string::npos) && (openPos1 == std::string::npos) ){ logDebug("parseInterval()", "No left brackets found!"); assertion(false); } if (closedPos1 == std::string::npos){ first = openPos1; } if (openPos1 == std::string::npos){ first = closedPos1; } if ( (closedPos1 != std::string::npos) && (openPos1 != std::string::npos) ){ first = std::min(closedPos1,openPos1); } // determine right bracket position if ( (closedPos2 == std::string::npos) && (openPos2 == std::string::npos) ){ logDebug("parseInterval()", "No right brackets found!"); assertion(false); } if (closedPos2 == std::string::npos){ last = openPos2; } if (openPos2 == std::string::npos){ last = closedPos2; } if ( (closedPos2 != std::string::npos) && (openPos2 != std::string::npos) ){ last = std::min(closedPos2,openPos2); } // check validity if (first >= last){ logDebug("parseInterval()", "Right brackets before left brackets!"); assertion(false); } if ( (semicolonPos <=first) || (semicolonPos >= last) || (semicolonPos == std::string::npos) ){ logDebug("parseInterval()", "No valid semicolon separation could not be detected!"); assertion(false); } // find out type of brackets if (first == closedPos1){ _isOpen(2*d) = false; } else { _isOpen(2*d) = true; } if (last == closedPos2){ _isOpen(2*d+1) = false; } else { _isOpen(2*d+1) = true; } // get start and end interval and set offset and width of box range number1 = interval.substr(first+1,semicolonPos-1-first); number2 = interval.substr(semicolonPos+1,last-1-semicolonPos); _offset(d) = getNumbers->convertValueStringToDouble( number1 ); _width(d) = getNumbers->convertValueStringToDouble(number2) - _offset(d); logDebug("parseInterval()", "Number1: " << number1 << " offset " << d << ": " << _offset(d)); logDebug("parseInterval()", "Number2: " << number2 << " width " << d << ": " << _width(d)); // remove this part from string interval = interval.substr(last+1); // find sign 'x' and next left bracket if (d < DIMENSIONS-1){ size_t closedNext = interval.find("["); size_t openNext = interval.find("("); first = interval.find("x"); if ( (closedNext == std::string::npos) && (openNext == std::string::npos) ){ logDebug("parseInterval()", "No new left brackets found!"); assertion(false); } if (closedNext == std::string::npos){ last = openNext; } if (openNext == std::string::npos){ last = closedNext; } if ( (closedNext != std::string::npos) && (openNext != std::string::npos) ){ last = std::min(closedNext,openNext); } if (last <= first){ logDebug("parseInterval()", "No 'x' between intervals could be found!"); assertion(false); } // remove all just until the first letter behind 'x' interval = interval.substr(first+1); } logDebug("parseInterval()", "Rest to parse: " << interval); } // check width for (int d = 0; d < DIMENSIONS; d++){ if (tarch::la::smaller(_width(d),0.0)){ logDebug("parseInterval()", "Width of box is smaller than zero!"); assertion(false); } } }
int main() { cout << "以下实验是规定了Document的值,测试时可以自行改变其值与测试内容" << endl; char b1[5] = { 'i', '9', '5', ',', 's' }; Line a1 (b1, b1 + 5); char b2[7] = { ' ', 'c', 'r', 'l', ' ','c','o' }; Line a2(b2,b2+7); char b3[6] = { '8','w', ' ', 'l', '*', 'l'}; Line a3(b3, b3 + 6); list<Line>answer; answer.push_back(a1); answer.push_back(a2); answer.push_back(a3); Document my_doc(answer); Document tmp = my_doc; cout << "原来文件为:" << endl; print(tmp); cout << endl; cout << "文件的字符数为:" << number(tmp) << endl; cout << "文件的字数为(根据第一种算法):" << number1(tmp) << endl; cout << "其中字母序列(第二种算法):" << number2(tmp)<<endl; const string pre= "i7"; cout << "查找单词为:" << pre<<endl; Text_iterator p = find_text(tmp, pre); if (p==tmp.end() ) { cout << "不存在该单词" << endl; } else { cout << "存在该单词" << endl; int length = pre.length(); string now = "wa56 ker"; cout << "替换为:" << now << endl; cout << "替换后的文件为:" << endl; p.change(length, now); print(tmp); cout << endl; cout << "文件的字符数为:" << number(tmp) << endl; cout << "文件的字数为(根据第一种算法):" << number1(tmp) << endl; cout << "其中字母序列(第二种算法):" << number2(tmp) << endl; } tmp = my_doc; string pres = "crl"; cout << "查找单词为:" << pres << endl; Text_iterator s = find_text(tmp, pres); if (s == tmp.end()) { cout << "不存在该单词" << endl; } else { cout << "存在该单词" << endl; int length = pres.length(); string now = "wa56 er"; cout << "替换为:" << now << endl; cout << "替换后的文件为:" << endl; s.change(length, now); print(tmp); cout << endl; cout << "文件的字符数为:" << number(tmp) << endl; cout << "文件的字数为(根据第一种算法):" << number1(tmp) << endl; cout << "其中字母序列(第二种算法):" << number2(tmp) << endl; } getchar(); getchar(); getchar(); }
int main(int argc, const char *argv[]) { options::single<int> number('N', "number", "some number", 0); options::single<int> number2('k', "kumber", "some other number", 0, {0, 3, 3}); options::map<int, std::vector<std::pair<std::string, int> > > numbers('m', "numbers", "several numbers"); options::map<std::string, std::list<std::pair<std::string, std::string> > > strings('s', "strings", "several strings"); options::single<const char *>cs('c', "cstring", "a c string", "", {"bla", "blubb"}); options::single<std::string>Cs('C', "Cstring", "a C++ string", "", {"bla", "blubb"}); options::container<double> dnums('d', "doubles", "double numbers"); // options::container<const char*, std::list<const char*>> stringl('S', "listString", "list of strings"); options::container<std::string, std::list<std::string>> stringS('X', "liststring", "list of std::strings"); options::single<double> complexDescription('\0', "ComplexDescription", "Pass here the Bremsstrahl-Tagging-Hodoscope-Engineering-Assemply-Rate in Hz", 84.); options::single<double> moreComplexDescription('\0', "MoreComplexDescription", "very complicated example option with very long explanation to illustrate automatic wrapping in help output when the explanations become very long and would break readability otherwise.", 42.); options::single<double> evenMoreComplexDescription('\0', "EvenMoreComplexDescription", "very complicated example option with very long explanation containing averylongwordwhichisunbreakableandthustriggersforcefulwordwrappinginaninconvenientplacetokeepthingssomehowatleastabitreadable.", 21.); options::single<options::postFixedNumber<size_t>> size('\0', "size", "a size"); options::single<std::chrono::system_clock::time_point> date('\0', "date", "a date"); options::single<std::chrono::duration<long>> dur('\0', "dur", "a duration"); options::single<bool> lateOption('\0', "lateOption", "try to book an option late", false); cs.fForbid(&Cs); Cs.fForbid(&cs); options::container<std::chrono::system_clock::time_point> dates('\0', "dates", "list of dates"); options::OptionsForTApplication TApplicationOptions(argv[0]); options::positional<options::single<float>>posNumber(10, "posnumber", "positional float number", 0); options::positional<options::container<std::string>>files(20, "files", "positional file list"); options::positional<options::single<const char *>>dest(30, "dest", "positional destination file", ""); options::parser parser("option parsing example"); parser.fRequire(&number); auto unusedOptions = parser.fParse(argc, argv); TApplicationOptions.fFinalize(unusedOptions.begin(), unusedOptions.end()); for (auto & unusedOption : unusedOptions) { std::cout << "unused option : '" << unusedOption << "'" << std::endl; } for (auto & num : numbers) { std::cout << " number '" << num.first << "' is '" << num.second << "'\n"; } for (auto & str : strings) { std::cout << " string '" << str.first << "' is '" << str.second << "'\n"; } for (double & dnum : dnums) { std::cout << " double number '" << dnum << "'\n"; } // for (auto & it : stringl) { // std::cout << " list string '" << it << "'\n"; //} for (auto & it : stringS) { std::cout << " list std::string '" << it << "'\n"; } std::cout << "and the time variable is:"; date.fWriteValue(std::cout); auto timebuf = std::chrono::system_clock::to_time_t(date); std::cout << ", that is " << std::ctime(&timebuf); std::cout << "the duration is: "; dur.fWriteValue(std::cout); std::cout << " or " << std::chrono::duration_cast<std::chrono::hours>(dur).count() << " hours \n"; if (lateOption) { options::single<bool> optionLate('\0', "lateOptionTest", "option booked late", false); } return number; }