zoukankan      html  css  js  c++  java
  • P2064进制转换

    题目:https://www.luogu.org/problemnew/show/P2084

    既然这道题放在字符串类型里,那么这里的N肯定得用字符数组来储存(这样也方便输出)。

    那么我们不妨定义一个字符串数组a[1001](他说n的位数在1000以下),输出格式就是a[i]*m*k+.......(k为m的几次方),接下来就是求k了。我们发现,最低位的k是0,那么假设n有x位,最高位的k就是x-1.

    所以每输出一次,k就要减一。

    话不多说,代码奉上:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    int m,k;
    char a[1001];
    int main()
    {cin>>m>>a;
    k=strlen(a)-1;//最高位的k
    int t=strlen(a);
      for(int i=0;i<t;i++)
      {if(a[i]!='0')//0要省略
       cout<<a[i]<<"*"<<m<<"^"<<k; 
      if(k!=0&&a[i+1]!='0')cout<<"+";//"+"是个恶心的玩意,要加特判
      k--;
      }
     
      
  • 相关阅读:
    Title
    Title
    Title
    Title
    Python生成随机验证码
    Time模块和datetime模块
    For循环的实质
    Python函数
    集合set
    字符串内置方法的使用
  • 原文地址:https://www.cnblogs.com/lcez56jsy/p/10452912.html
Copyright © 2011-2022 走看看