Poj1220 (high-precision arbitrary hexadecimal conversion)

Source: Internet
Author: User

High-Precision arbitrary Conversion


The code is found in discuss and is said to have been written by maigo.

Ultra-Simplified !!

In my first writing, I first converted the n-base to the 10-base, and then converted the n-base to the m-base...

Sadly, it was written for a long time. It was not correct yet !!!

Code:

 

#include <stdio.h>   #include <string.h>   const int maxn = 1000;  int  t[maxn], A[maxn];  char str1[maxn], str2[maxn];  int n, m;  void solve()  {      int i, len, k;      len = strlen(str1);      for(i=len; i>=0; --i) t[len-1-i] = str1[i] -(str1[i]<58 ? 48: str1[i]<97 ? 55: 61);      for(k=0; len;) {          for(i=len; i>=1; --i) {              t[i-1] +=t[i]%m*n;              t[i] /= m;          }          A[k++] = t[0] % m;          t[0] /=m;          while(len>0&&!t[len-1])  len--;      }      str2[k] =NULL;      for(i=0; i<k; i++)          str2[k-1-i] = A[i]+(A[i]<10 ? 48: A[i]<36 ? 55:61);  }    int main()  {      int T;  //    freopen("in.txt","r",stdin);       scanf("%d",&T);      while(T--) {          scanf("%d%d%s",&n, &m, str1);          solve();          printf("%d %s\n%d %s\n\n", n, str1, m, str2);      }      return 0;  }  

 

Related Article

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.