Example #1
0
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;
}
Example #2
0
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');
}
Example #3
0
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;
}
Example #4
0
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;
}
Example #5
0
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;
}
Example #6
0
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);
}
Example #7
0
int countto(int n)
{
	int ds, pow2;
	ds = digits(n);
	for (pow2 = 1; ds > 0; ds--) pow2 *= 2;
	return pow2;
}
Example #8
0
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;
}
Example #9
0
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);
}
Example #10
0
/*
 *  *_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();
	}
}
Example #11
0
File: main.c Project: oswjk/euler-c
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;
}
Example #12
0
/** \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;
}
Example #13
0
/**
 * 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, '*');
}
Example #14
0
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();
}
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;
}
Example #16
0
int persistence( int n, int i ){
	
	if( n <= 9 ){
		n = digits(n);
		i++;
	}
	return i;
}
Example #17
0
/**
 * 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;
}
Example #18
0
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;
}
Example #19
0
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);
}
int main()
{
	long n,b;
	while(scanf("%ld%ld",&n,&b)!=EOF)
	{
		printf("%ld %ld\n",zer(n,b),digits(n,b));
	}
	return 0;
}
Example #21
0
//
//returns sum of digits from 0 to n
long long sumdigs(int n)
{
    long long sum = 0, i;
    for(i = 0; i <= n; i++) { 
        //printf("%d = %d\n", i, digits(i));
        sum = sum + digits(i);
    }
    return sum;
}
Example #22
0
int main() {
	for (int d = 5; d <= 5; ++d) {
		const int t = digits(d); // 10000

		for (int a = 0; a < d; ++a) {
			//
		}
	}
}
Example #23
0
String& append(String& str, const Ulong& n)

{
  static String cs(digits(ULONG_MAX,10));

  cs.setLength(sprintf(cs.ptr(),"%lu",n));
  append(str,cs);
  return str;
}
Example #24
0
String& append(String& str, const unsigned& n)

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

  cs.setLength(sprintf(cs.ptr(),"%u",n));
  append(str,cs);

  return str;
}
BOOST_XINT_RAWINT_TPL
BOOST_XINT_RAWINT& BOOST_XINT_RAWINT::operator&=(const BOOST_XINT_RAWINT &n) {
    std::size_t len = (std::min)(length, n.length);
    const digit_t *ns = n.digits(), *nse = ns + len;
    digit_t *t = digits(len, realloc::extend);
    while (ns != nse) *t++ &= *ns++;
    length = len;
    trim();
    return *this;
}
Example #26
0
string truncateText(string name, int length, uint quantity)
{
	stringstream output;
	
	if (quantity == 1) {
		if (name.length() <= length)
			output << name;
		else
			output << name.substr(0, length - 3) << "...";
	} else {
		if (name.length() <= (length - (4 + digits(quantity)))) {
			output << name << " (x" << quantity << ")";
			
		} else
			output << name.substr(0, length - (7 + digits(quantity))) << "... (x" << quantity << ")";
	}
	
	return output.str();
}
Example #27
0
/* format the string of the metadata of the hidim
 * length is changed to hold the length of the torrent file */
char *create_metadata(unsigned int *length, int line_length, const char* torrent) {
    struct stat buf;
    int len_filename;
    char *metadata, *sha1sum;

    const char *filename = basename(torrent);
    len_filename = strlen(filename);
    stat(torrent, &buf); // should not failed, checked before
    *length = buf.st_size;

    metadata = calloc(HIDIM_KEY_SIZE + digits(line_length) + digits(*length) +
           digits(len_filename) + len_filename + 40 + 8 + 1, sizeof(char));
    sha1sum = hexa_sha1sum_file(torrent);
    sprintf(metadata, "%si%de%d:%s40:%si%de", HIDIM_KEY_STRING, line_length, 
            len_filename, filename, sha1sum, *length);
    free(sha1sum);

    return metadata;
}
Example #28
0
void print_intb(unsigned int n, int base, unsigned int col, unsigned int row) {
    // check base <= 16
    char numbers[16] = "0123456789ABCDEF";

    int d = digits(n, base);
    do {
        putc(numbers[n % base], col+d-1, row);
        n /= base;
        d--;
    } while (n > 0);
}
Example #29
0
/*
 * Convert number to human readable string, i.e.
 *
 *   - 12345 ==> 12.3 thousand
 *   - 1234567 ==> 1.2 million
 *   - etc.
 *
 * using the SHORT SCALE format (i.e., English
 * variants such as "billion" = 10^9, instead of
 * "milliard".
 */
static const char* sscale(double n, int decimals = 1)
{
  static char s[32];
  static const char* name[] = {
    "",
    "thousand",
    "million",
    "billion",
    "trillion",
    "quadrillion",
    "quintillion",
    "sextillion",
    "septillion"
  };

  int exp = digits(n) <= 4? 0 : 3*((digits(n)-1)/3);
  sprintf(s, "%1.*lf %s", decimals, n/pow(10, exp), name[exp/3]);

  return s;
}
Example #30
0
bool isTruncable(int n) {	
	if(isPrime(n)) {
		int i = 10, d = digits(n), b = pow(10, d - 1);
		while(i <= pow(10, d - 1)) {
			if(!(isPrime(n % i) && isPrime(n / i)))				
				return false;
			i *= 10;
		}
		return true;
	}
	return false;
}