Sponsored Content
Top Forums Programming Programming Challenges - A List Post 302120846 by Franklin52 on Friday 8th of June 2007 02:08:45 PM
Old 06-08-2007
Quote:
Originally Posted by blowtorch
Challenge: DRAM

Difficulty: Easy to Medium in C, Easy in perl/python

As the problem says, the value of the palindrome may exceed your system's defined integer size in C/C++.
My trial:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void palindrome(char *p, int value);

int main (int argc, char *argv[])
{
    int val[20];
    int i, n;
    char pal[20];

    n = 0;

    while (n < 20) {
        scanf("%d", &val[n]);
	if(val[n] == -1) {
	    break;
	}
	n++;
    }
    
    for(i = 0; i < n; i++) {
	pal[0] = '\0';
	palindrome(pal, val[i]);

	if(pal[0]) {
	    printf("Initial value: %d gives palindrome %s\n",val[i], pal);
        }
        else {
	    printf("Initial value: %d no palindrome found\n",val[i]);
        }
    }

    return(0);
}

void palindrome(char *p, int value)
{
    long pal;
    char str[20], rts[20];
    int i, j, len, nel; 

    pal = value;

    for(j = 0; j < 1000; j++) {
        sprintf(str, "%d", pal); 
	len = strlen(str);
        nel = len-1;

	for(i = 0; i < len; i++) {
	    rts[i] = str[nel];
	    nel--;
        }
	rts[len] = '\0';
        nel = len/2;

	if(!strncmp(str, rts, nel)) {
	    strcpy(p, str);    
	    return;
	}
	pal = pal + strtol(rts, 0, 0);
    }
    p[0] = '\0';
}

Regards
 

3 More Discussions You Might Find Interesting

1. AIX

AIX 6.1 IDSLDAP Installation Challenges

Please bare with me, since I am new to AIX and LDAP. I am attempting to install idsldap server on our AIX 6.1 NIM server. I installed the following packages: root@nim(/)# lslpp -l|grep ldap db2_08_01.ldap 8.1.1.80 COMMITTED DB2 LDAP Support idsldap.clt64bit61.rte 6.1.0.17 COMMITTED... (6 Replies)
Discussion started by: ecollins
6 Replies

2. UNIX for Advanced & Expert Users

Challenges in finding and copying the block

Hi, I have a below challenging task where iam unable to find the block and copy the same into a file. I tried my luck,howver iam unable to reach the first and second step..Can anyone help me with a clue or with the commands so that i can give a try. 1. search the <number>9966993366</number>... (2 Replies)
Discussion started by: cskumar
2 Replies

3. Shell Programming and Scripting

Korn shell script - SQL statement challenges

Hi scripting experts. I have some coding challenges that I'm hoping you can help me out. I have one file#1 that contains the following sql statement that spans over multiple lines: sql Select /*+ use_has(a,b) */ * from customer a, customer_address b where a.id = b.id... (1 Reply)
Discussion started by: pchang
1 Replies
KML2GMT(1gmt)						       Generic Mapping Tools						     KML2GMT(1gmt)

NAME
kml2gmt - Extract GMT table data from Google Earth KML files SYNOPSIS
kml2gmt [ infile ] [ -V ] [ -Z ] [ -:[i|o] ] [ -bo[s|S|d|D[ncol]|c[var1/...]] ] DESCRIPTION
kml2gmt reads a Google Earth KML file and outputs a GMT table file. Only KML files that contain points, lines, or polygons can be pro- cessed. This is a bare-bones operation that aims to extract coordinates and possibly the name and description tags of each feature. The main use intended is to capture coordinates modified in Google Earth and then reinsert the modified data into the original GMT data file. For a more complete reformatting, consider using ogr2ogr -f "GMT" somefile.gmt somefile.kml. infile Name of the KML file to work on. If not given, standard input is read. OPTIONS
No space between the option flag and the associated arguments. -Z Output the altitude coordinates as GMT z coordinates [Default will output just longitude and latitude]. -V Selects verbose mode, which will send progress reports to stderr [Default runs "silently"]. -: Toggles between (longitude,latitude) and (latitude,longitude) input and/or output. [Default is (longitude,latitude)]. Append i to select input only or o to select output only. [Default affects both]. -bo Selects binary output. Append s for single precision [Default is d (double)]. Uppercase S or D will force byte-swapping. Option- ally, append ncol, the number of desired columns in your binary output file. EXAMPLES
SEE ALSO
gmtdefaults(1), GMT(1), img2google(1), ps2raster(1) gmt2kml(1) GMT 4.5.7 15 Jul 2011 KML2GMT(1gmt)
All times are GMT -4. The time now is 09:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy