int lengthOfLastWord(string s) { string::const_reverse_iterator wordEnd = s.crbegin(); while (wordEnd != s.crend() && *wordEnd == ' ') { ++wordEnd; } string::const_reverse_iterator wordBegin = wordEnd; while (wordBegin != s.crend() && *wordBegin != ' ') { ++wordBegin; } int len = wordBegin - wordEnd; return len; }
bigint::bigint (const string& that){ auto itor = that.cbegin(); bool isnegative = false; if (itor != that.cend() and *itor == '_') { isnegative = true; ++itor; } //cout << "bigint ctor: making bigint?" << endl; auto itorator = that.crbegin(); //int newval = 0; digit_t temp;// = '9'; auto end = that.crend(); if(isnegative) --end; while (itorator != end){ //cout << "bigint ctor:" << temp << "<- temp" << endl; /////////////////////////////////////////////////////////////// temp = *itorator;/////hmmmmmmmm............./////////// /////////////////////////////////////////////////////////////// //cout << "bigint ctor:" << temp << "<- temp" << endl; //temp = static_cast<digit_t>(that.at(itorator)); big_value.push_back(temp); itorator++; // newval = newval * 10 + *itor++ - '0'; } if(isnegative) negative = true; else negative = false; //DEBUGF ('~', this << " -> " << big_value) }
bool CFastaDeflineReader::x_ExcessiveSeqDataInTitle(const string& title, TFastaFlags fasta_flags) { if (fasta_flags & CFastaReader::fAssumeProt) { return false; } // Check for nuc or aa sequence at the end of the title const TSeqPos kWarnNumNucCharsAtEnd = 20; const TSeqPos kWarnNumAminoAcidCharsAtEnd = 50; // Check for nuc sequence if (title.length() > kWarnNumNucCharsAtEnd) { TSeqPos numNucChars = 0; for (auto rit=title.crbegin(); rit!=title.crend(); ++rit) { if (!s_ASCII_IsUnAmbigNuc(*rit) && (*rit != 'N')) { break; } ++numNucChars; } if (numNucChars > kWarnNumNucCharsAtEnd) { return true; } } // Check for Aa sequence if (title.length() > kWarnNumAminoAcidCharsAtEnd) { TSeqPos numAaChars = 0; for (auto rit=title.crbegin(); rit!=title.crend(); ++rit) { const auto ch = *rit; if ( !(ch >= 'A' && ch <= 'Z') && !(ch >= 'a' && ch <= 'z') ) { break; } ++numAaChars; } if (numAaChars > kWarnNumAminoAcidCharsAtEnd) { return true; } } return false; }
string addBinary(string a, string b) { const int base = 2;//进制 int length = max(a.length(), b.length()); string ans; int c = 0;//进位 auto ita = a.crbegin(); auto itb = b.crbegin(); while(length--){ int numa = 0, numb = 0; if(ita != a.crend()){ numa = (*ita++) - '0'; } if(itb != b.crend()){ numb = (*itb++) - '0'; } ans.push_back((numa + numb + c) % base + '0'); c = (numa + numb + c) / base; } if(c){ ans.push_back('1'); } reverse(ans.begin(), ans.end()); return ans; }
decimal::decimal(const string& val) { digits.reserve(val.size()); for (auto it = val.crbegin(); it != val.crend(); ++it) { char c = *it; if (c == ',') { continue; } if (c >= '0' && c <= '9') { digits.push_back((digit) (c - '0')); } else { throw invalid_argument("Not a digit: " + string{c}); } } remove_lz(); }
// Add the string of alignment characters to the alignment in reverse order void Alignment_t::addStringReversed(string & s) { string::const_reverse_iterator rit = s.crbegin(); string::const_reverse_iterator rend = s.crend(); char c; size_t n = 1; while (rit < rend) { n = 1; c = *rit; // Check for the same consecutive characters while ( c == *(++rit)) n++; this->addSymbol(c, n); } }
bigint::bigint (const string& that) { auto itor = that.cbegin(); bool isnegative = false; negative = false; digit_t digit;// if (*itor == '_') { isnegative = true; negative = true;// //++itor; } int newval = 0; auto ritor = that.crbegin(); while (ritor != that.crend() and *ritor != '_' and *ritor != '+') { digit = (*ritor - '0');// newval = newval * 10 + *ritor++ - '0'; big_value.push_back(digit);// //cout << digit + '0' << endl; } long_value = isnegative ? - newval : + newval; //DEBUGF ('~', this << " -> " << long_value) }