zoukankan      html  css  js  c++  java
  • c语言实现:4和7幸运数字的题

    #include <stdio.h>
    #include <math.h>
    #include <vector>
     
    using namespace std;
    
    int main()
    {
        int i;
         
        int x,y,z;
        char *p;
        double w=2;
        int temp;
        char ch;
    
        vector<int> vec1;
    
        vector<unsigned int> vec2;
        
        vector<int> vec3;
        
        scanf("%d",&i);
    
        for(x=0;x<i;x++)
        {
        scanf(
    "%d",&temp);   vec1.push_back(temp);
    }
    for(x=0;x<i;x++) { for(y=1;y<32;y++) { if((pow(w,y)-1)*2>=vec1[x] && (pow(w,y-1)-1)*2<=vec1[x]) break; } vec2.push_back(y); } for(x=0;x<i;x++) { vec3.push_back(vec1[x]-2*(pow(w,y-1)-1)-1); } for(x=0;x<i;x++) {
         //内存的管理问题 p
    = (char*)malloc(sizeof(char)*(vec2[x]+1)); memset(p,0,vec2[x]+1); for(y=0;y<vec2[x];y++) { if(vec3[x]&0x1==1) p[y]=7+'0'; else p[y]=4+'0'; vec3[x] = vec3[x]>>1; } for(y=0,z=vec2[x]-1;y<vec2[x]/2;y++,z--) { ch = p[y]; p[y]= p[z]; p[z]=ch; } printf("%s ",p); } }
  • 相关阅读:
    Javascript
    CSS3新增特性HTML标签类型
    HTML5新增的标签
    prototype __proto__ Function
    oninput
    extend
    hasOwnProperty()
    this prototype constructor
    Array类型判断
    指针
  • 原文地址:https://www.cnblogs.com/dongzhuangdian/p/5843839.html
Copyright © 2011-2022 走看看