• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ digits函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中digits函数的典型用法代码示例。如果您正苦于以下问题:C++ digits函数的具体用法?C++ digits怎么用?C++ digits使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了digits函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: main

int main(){
    //TODO: faster
    uint max = 1000000000;
    uint count = 0;
    for(uint i = 10; i < max; i++){
        if(i % 10 != 0){
            string s = intToString(i);
            if(((int)(s[0]) + (int)(s[s.size() - 1])) % 2 != 0){
                uint reverse = reverseInt(i);
                vector<uint> d = digits(i + reverse);
                int j = 8;
                bool isRev = true;
                do{
                    if(d[j] > 0){
                        isRev = false;
                    }
                    j -= 2;
                }while(isRev && j >= 0);

                if(isRev){
                    count++;
                }
            }
        }
    }

    cout << count << endl;

    return 0;
}
开发者ID:hugocartwright,项目名称:project-euler,代码行数:30,代码来源:prob145.cpp


示例2: main

void main()
{
clrscr();
int choice;
char ch;
do{clrscr();
cout<<"\n MENU ";
cout<<"\n 1.CREATE";
cout<<"\n 2.DISPLAY";
cout<<"\n 3.NO OF UPPER CASE CHARACTERS ";
cout<<"\n 4.NO OF VOWELS";
cout<<"\n 5.NO OF DIGITS";
cout<<"\n 6.NO OF WORDS";
cout<<"\n 7.NUMBER OF LINES";
cout<<"\n enter ur choice";
cin>>choice;
switch(choice)
{
case 1:create();break;
case 2:display();break;
case 3:uppercase();break;
case 4:vowels();break;
case 5:digits();break;
case 6:words();break;
case 7:lines();break;
default: cout<<"\n wrong choice entered..!!";
}
cout<<"\n do you want to continue...??";
cin>>ch;
}
while(ch=='y'||ch=='Y');
}
开发者ID:raghavjajodia,项目名称:SchoolProgramming,代码行数:32,代码来源:Q21.CPP


示例3: factorial

vector<int> factorial( int n ) {
	// Initialize a vector with NUMDIGITS 0's.
	vector<int> digits( NUMDIGITS, 0 );
	int size = 1;
	digits[0] = 1;

	// This loop mimics multiplication by hand.
	for( int i = 2; i <= n; i++ ) {
		int carry = 0;

		for( int j = 0; j < size; j++ ) {
			int prod = digits[j] * i + carry;
			digits[j] = prod % 10;
			carry = prod / 10;
		}

		while( carry != 0 ) {
			digits[size] = carry % 10;
			carry /= 10;
			size++;
		}
	}

	return digits;
}
开发者ID:Eppie,项目名称:euler,代码行数:25,代码来源:Euler20.cpp


示例4: handle_operand

int handle_operand(int operand, 
                   BYTE negate, ld_line_t line) {
    int rv = PLC_OK;
    BYTE byte = 0;
    BYTE bit = 0;
    if (operand >= OP_INPUT && operand < OP_CONTACT){	//valid input symbol
		rv = extract_arguments(line->buf + (++line->cursor), 
		                            &byte, 
		                            &bit);       
		//extract_number(line->buf, ++line->cursor);
		if (rv == PLC_OK){
			/*byte + slash + bit*/
			line->cursor += digits((unsigned int)byte) + 2; 
			
			item_t identifier = mk_identifier(operand, 
			                                byte, 
			                                bit);
			line->stmt = mk_expression(identifier,
			                                 line->stmt,
			                                 IL_AND,
			                                 negate?IL_NEG:IL_NORM);
		} else {
			rv = ERR_BADINDEX;
			line->status = STATUS_ERROR;		    
		}
	} else {
		rv = ERR_BADOPERAND;
	    line->status = STATUS_ERROR;
	}
	line->cursor++;
    return rv;
}
开发者ID:kalamara,项目名称:plcemu,代码行数:32,代码来源:parser-ld.c


示例5: fprintf

void OrientedGraph::print(FILE* file) const

/*
  Does a printout of the graph on the file.
*/

{
  fprintf(file,"size : %lu\n\n",size());

  int d = digits(size(),10);

  for (Vertex x = 0; x < size(); ++x) {
    const EdgeList& e = edge(x);
    fprintf(file,"%*lu : ",d,x);
    for (Ulong j = 0; j < e.size(); ++j) {
      fprintf(file,"%*lu",d,e[j]);
      if (j < e.size()-1) { /* there is more to come */
	fprintf(file,",");
      }
    }
    fprintf(file,"\n");
  }

  fprintf(file,"\n");

  return;
}
开发者ID:tscrim,项目名称:coxeter,代码行数:27,代码来源:wgraph.cpp


示例6: digits

DigitField::DigitField(const Font& font, unsigned int maxDigits, char fillChar)
{
	maxDigits = maxDigits == 0 ? 1 : maxDigits;

	m_number.resize(maxDigits);

	std::string digits("0123456789");
	digits.push_back(fillChar);

	float maxDigitAspectRatio = 0.0f;

	for (size_t i = 0; i < maxDigits; ++i)
	{
		std::vector<std::shared_ptr<StaticChar>> digitLookup;

		for (char digit : digits)
		{
			assert(font.HasGlyph(digit));
			digitLookup.push_back(std::make_shared<StaticChar>(font, digit));
			maxDigitAspectRatio =
				std::max(maxDigitAspectRatio, font.GetAspectRatio(digit));
		}

		m_digitLookups.push_back(digitLookup);
	}

	m_aspectRatio = maxDigits * maxDigitAspectRatio;

	SetNumber(0);
}
开发者ID:mathall,项目名称:nanaka,代码行数:30,代码来源:DigitField.cpp


示例7: countto

int countto(int n)
{
	int ds, pow2;
	ds = digits(n);
	for (pow2 = 1; ds > 0; ds--) pow2 *= 2;
	return pow2;
}
开发者ID:TheTomster,项目名称:euler,代码行数:7,代码来源:e51.c


示例8: digits

std::vector<int> EulerUtility::factorialDigits(int n)
{
	std::vector<int> digits(1, 1);

	for (int i = 1; i <= n; ++i)
	{
		for (unsigned j = 0; j < digits.size(); ++j)
			digits[j] *=i;

		for (unsigned j = 0; j < digits.size(); ++j)
		{
			if (digits[j] >= 10)
			{
				int carry = (digits[j] - (digits[j] % 10)) / 10;
				digits[j] = digits[j] % 10;

				if (j == digits.size() - 1)
					digits.push_back(carry);
				else
					digits[j + 1] += carry;
			}
		}
	}

	return digits;
}
开发者ID:mpizzzle,项目名称:ProjectEuler,代码行数:26,代码来源:EulerUtility.cpp


示例9: main

int main(int argc, char** argv) {
    c = 0;
    
    //SAVING PID TO FILE :
    FILE *myfile;
  
    myfile = fopen("listenPID.txt","w");
    if (!myfile)
    {
        printf("Unable to open file!");
        return 1;
    }
    pid_t listenPID = getpid();
    char str[10];

    sprintf(str, "%d", listenPID);
    fwrite(str, sizeof(char),digits(listenPID) , myfile);
    fclose(myfile);
    //END OF WRITING
    
    if(signal(SIGUSR1, handler) == SIG_ERR)
        printf("\n SignalError.\n");
    if(signal(SIGUSR2, handler) == SIG_ERR)
        printf("\n SignalError.\n");
    
    while(1) {    
    
    } 
    
    return (EXIT_SUCCESS);
}
开发者ID:OlgaSlota,项目名称:OperatingSystems,代码行数:31,代码来源:listenB.c


示例10: i_procstates

/*
 *  *_procstates(total, brkdn, names) - print the process summary line
 *
 *  Assumptions:  cursor is at the beginning of the line on entry
 */
void
i_procstates(int total, int *brkdn)
{
	if (screen_length > 2 || !smart_terminal) {
		int i;
		char procstates_buffer[MAX_COLS];

		move(1, 0);
		clrtoeol();
		/* write current number of processes and remember the value */
		printwp("%d processes:", total);

		if (smart_terminal)
			move(1, 15);
		else {
			/* put out enough spaces to get to column 15 */
			i = digits(total);
			while (i++ < 4) {
				if (putchar(' ') == EOF)
					exit(1);
			}
		}

		/* format and print the process state summary */
		summary_format(procstates_buffer, sizeof(procstates_buffer), brkdn,
		    procstate_names);

		addstrp(procstates_buffer);
		putn();
	}
}
开发者ID:UNGLinux,项目名称:Obase,代码行数:36,代码来源:display.c


示例11: is_palindrome

int is_palindrome(int i)
{
    list_t *d = NULL;
    int len = 0;
    int j = 0;

    if (i < 10)
        return 1;

    d = digits(i);
    len = list_len(d);

    // printf("i:%d\n", i);

    for (j = 0; j < len/2; ++j)
    {
        int *a = (int*)list_get_n(d, j);
        int *b = (int*)list_get_n(d, len-1-j);

        // printf("a:%d b:%d\n", *a, *b);

        if (*a != *b)
        {
            return 0;
        }
    }

    list_free(d, list_free_int);

    return 1;
}
开发者ID:oswjk,项目名称:euler-c,代码行数:31,代码来源:main.c


示例12: digits

/** \fn DBUtil::ParseDBMSVersion(void)
 *  \brief Parses m_versionString to find the major, minor, and point version.
 */
bool DBUtil::ParseDBMSVersion()
{
    if (m_versionString.isEmpty())
        if (!QueryDBMSVersion())
            return false;

    bool ok;
    QString section;
    int pos = 0, i = 0;
    int version[3] = {-1, -1, -1};
    QRegExp digits("(\\d+)");

    while ((i < 3) && ((pos = digits.indexIn(m_versionString, pos)) > -1))
    {
        section = digits.cap(1);
        pos += digits.matchedLength();
        version[i] = section.toInt(&ok, 10);
        if (!ok)
            version[i] = -1;
        i++;
    }

    m_versionMajor = version[0];
    m_versionMinor = version[1];
    m_versionPoint = version[2];

    return m_versionMajor > -1;
}
开发者ID:StefanRoss,项目名称:mythtv,代码行数:31,代码来源:dbutil.cpp


示例13: Rows

/**
 * Paint the window status
 */
void EditorWindow::PaintEditorStatus(void)
{
	char buf[256];
	int r = Rows() - 1;
	
	if (editor == NULL) return;

	UseFrameStyle();

	
	// Clear the space
	
	tcw->OutHorizontalLine(r, 1, 14);
	
	
	// Print the cursor location
	
	snprintf(buf, sizeof(buf), " %d:%d ", editor->DocumentCursorRow(),
			 editor->DocumentCursorColumn());
	tcw->OutText(r, 9 - digits(editor->DocumentCursorRow()), buf);
	
	
	// Print the flags
	
	if (editor->OverwriteMode()) tcw->OutChar(r, 2, 'O');
	if (editor->Document()->Modified()) tcw->OutChar(r, 3, '*');
}
开发者ID:aific,项目名称:ape,代码行数:30,代码来源:EditorWindow.cpp


示例14: digits

void HUD::DrawDigits(Locus::RenderingState& renderingState, int value, int numDigits, float x, float y) const
{
   std::vector<int> digits(numDigits);

   for (int d = numDigits, denominator = 1; d >= 1; d--, denominator *= 10)
   {
      digits[d-1] = ( value/denominator ) % 10;
   }

   renderingState.transformationStack.Push();

   renderingState.transformationStack.LoadIdentity();
   renderingState.transformationStack.Translate( Locus::FVector3(x, y, 0.0) );

   for (int i = 0; i < numDigits; ++i)
   {
      textureManager->GetTexture(MPM::TextureManager::MakeDigitTextureName(digits[i]))->Bind();
      renderingState.shaderController.SetTextureUniform(Locus::ShaderSource::Map_Diffuse, 0);

      renderingState.transformationStack.UploadTransformations(renderingState.shaderController);
      digit.Draw(renderingState);

      renderingState.transformationStack.Translate( Locus::FVector3(digitWidth, 0.0, 0.0) );
   }

   renderingState.transformationStack.Pop();
}
开发者ID:ShacharAvni,项目名称:Minor-Planet-Mayhem,代码行数:27,代码来源:HUD.cpp


示例15: digits

BOOST_XINT_RAWINT_TPL
BOOST_XINT_RAWINT& BOOST_XINT_RAWINT::operator^=(const BOOST_XINT_RAWINT &n) {
    std::size_t len = (std::max)(length, n.length);
    if (length > n.length) {
        const digit_t *ns = n.digits(), *nse = ns + n.length;
        digit_t *t = digits(len, realloc::extend);
        while (ns != nse) *t++ ^= *ns++;
    } else {
        const digit_t *ns = n.digits(), *nse = ns + len;
        digit_t *t = digits(len, realloc::extend), *te = t + length;
        while (t != te) *t++ ^= *ns++;
        while (ns != nse) *t++ = *ns++;
        length = len;
    }
    trim();
    return *this;
}
开发者ID:vividos,项目名称:MultiplayerOnlineGame,代码行数:17,代码来源:andorxor.hpp


示例16: persistence

int persistence( int n, int i ){
	
	if( n <= 9 ){
		n = digits(n);
		i++;
	}
	return i;
}
开发者ID:edpack1980,项目名称:uml-auto-assessment,代码行数:8,代码来源:p39.c


示例17: to_string

/**
 * Converts a node to a c string.
 */ 
char* to_string(node* n) {
	if(n == NULL) {
		return NULL;
	}
	char* str = smalloc(digits(n->freq) + strlen(n->word) + 1);
	sprintf(str,"%s: %d",n->word,n->freq);
	return str;
}
开发者ID:Robotregent,项目名称:system-soft,代码行数:11,代码来源:wordcounter.c


示例18: append

String& append(String& str, const long& m)

{
  static String cs(digits(LONG_MAX,10)+1);

  cs.setLength(sprintf(cs.ptr(),"%ld",m));
  append(str,cs);
  return str;
}
开发者ID:tscrim,项目名称:coxeter,代码行数:9,代码来源:io.cpp


示例19: mt_note_set_fret

void mt_note_set_fret(MtNote* note, int fret)
{
  assert(note != NULL);
  assert(note->type == MT_NOTE_NONE);

  note->type = MT_NOTE_NOTE;
  note->fret = fret;
  note->size = digits(fret);
}
开发者ID:cknadler,项目名称:marktab-c,代码行数:9,代码来源:mt_note.c


示例20: main

int main()
{
	long n,b;
	while(scanf("%ld%ld",&n,&b)!=EOF)
	{
		printf("%ld %ld\n",zer(n,b),digits(n,b));
	}
	return 0;
}
开发者ID:sumous,项目名称:uva,代码行数:9,代码来源:10061+-+How+many+zero's+and+how+many+digits+.cpp



注:本文中的digits函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ dijkstra函数代码示例发布时间:2022-05-30
下一篇:
C++ digitalWriteFast函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap