USACO Dual Palindrome

Recommended for you: Get network issues from WhatsUp Gold. Not end users.
ID: nenusb1
TASK: dualpal
#include <stdio.h>
#include <string.h>

char numStr[12];
int ifPal(){
     int len = strlen(numStr);
     int i;
     for(i=0; i<len; i++){
           if(numStr[i] != numStr[len-1-i]) return 0;//use break is stupid!
     return 1;
void myItoa(int value, int base){
     int i=0;     
     int len = --i;
     numStr[len+1] = '\0';     
     char c[1];      
     while(value>=0 && i>=0){    
        int tmp = value % base;    
        value /= base;                  
        //convert single int to char
        numStr[len-i] = tmp+'0';       

int main(){
    int n, s;
    scanf("%d %d",&n,&s);
    int num, count;
    count = 0;
    for(num = s+1;count<n;num++){

       int base;
       int palCount = 0;
       for(base = 2; base<=10; base++){
         if(ifPal(numStr)){ palCount++;}
         if(palCount == 2) {printf("%d\n", num); count++; break;}
    return 0;

Reference resources

The original

char numStr[12]

Into a global variable, Execution before error is solved, don't konw why

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Xavier at January 22, 2014 - 12:33 PM