USACO 1.2 Dual Palindromes (retrieval, hexadecimal conversion)

Source: Internet
Author: User

USACO 1.2 Dual Palindromes (retrieval, hexadecimal conversion)

Cool nonsense, post code:

/* ID: twd30651 PROG: dualpal LANG: C ++ */# include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
Using namespace std; char s [1, 100]; int N, S; void gs (int num, int BASE) {int index = 0; while (num/BASE) {s [index ++] = "0123456789 ABCDEF" [num % BASE]; // It is easy to understand and easy to understand, A 17-byte String constant num = num/BASE is wasted;} s [index ++] = "0123456789 ABCDEF" [num % BASE]; s [index] = '\ 0';} bool isPalindromes () {size_t len = strlen (s ); if (s [0] = '0' & s [len-1] = '0') return false; for (size_t I = 0; I <= len/2; ++ I) {if (s [I]! = S [len-i-1]) return false;} return true;} int main (int argc, char * argv []) {freopen ("dualpal. in "," r ", stdin); freopen (" dualpal. out "," w ", stdout); scanf (" % d ", & N, & S); int count = 0; int fn = 0; for (int I = S + 1; ++ I) {fn = 0; for (int j = 2; j <= 10; ++ j) {if (fn <2) {memset (s, 0, sizeof (s); gs (I, j); if (isPalindromes () {fn ++; if (fn = 2) {printf ("% d \ n", I); count ++; break ;}}} if (count = N) break ;} return 0 ;}
    
   
  
 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.