比n大的最小不重复数
2024-10-01 01:35:21
void Calculate(int a)
{
int pa = a;
int count = ;
int b[] = {}; //将pa按位存储到数组b
while(pa > )
{
b[count++] = pa%;
pa = pa/;
}
bool flag = true; //是否有重复数
bool carryFlag = false; //是否产生进位 //从高位开始判断是否有重复数
int i,j,k;
count--;
for(i=count;i>;i--)
{
if(b[i] == b[i-])
{
flag = false;
b[i-]++; //有可能产生进位
if(b[i-]>)
carryFlag = true;
break;
}
} if(!flag) //如果存在重复位
{
int c = ;
//将低位重复数后面的数都变成0101....
for(j = i-;j>;j--)
{
b[j-] = c;
c = (c == ? :);
} //处理进位
if(carryFlag)
{
int carry = ;
for(j = i-;j<=count + ;j++)
{
b[j] = b[j] + carry;
if(b[j] >= )
{
carry = ;
b[j] = b[j] - ;
}
}
}
pa = ;
for(i = (count= ? count + :count);i >=;i--)
{
pa = pa * + b[i];
}
cout<<"the min no repeat number: "<<pa<<endl;
}
else
{
cout<<"the min no repeat number: "<<a<<endl;
return;
}
} 输入两个很大正数,输出它们的乘积
void Multiply(const char *a,const char *b)
{
assert(a!=NULL && b!=NULL);
int len_a = strlen(a);
int len_b = strlen(b);
int *c = new int[len_a+len_b];
memset(c,,sizeof(int) *(len_a+len_b));
for(int i=;i<len_a;i++)
{
for(int j=;j<len_b;j++)
{
c[i+j+] += (a[i]-'')*(b[j]-'');
}
}
for(int i=len_a+len_b-;i>;i--)
{
if(c[i]>=)
{
int carry = c[i]/;
c[i-] = c[i-] + carry;
c[i] = c[i] % ;
}
}
char *d = new char[len_a + len_b];
int i=;
while(c[i] == ) ++i;
int j;
for(j=;i<len_a+len_b;j++,i++)
{
d[j] = c[i] + '';
}
d[j] = '\0';
for(int i=;i<len_a+len_b;i++)
cout<<d[i];
cout<<endl;
}
最新文章
- [LeetCode] Bulls and Cows 公母牛游戏
- js④
- log4j 配置
- [BZOJ1061][Noi2008]志愿者招募
- Exception in thread ";AWT-EventQueue-0"; java.lang.IllegalThreadStateException
- gpfdist工具的初级使用
- Servlet&;JSP基础
- 【贪心】【POJ3154】墓地雕塑(Graveyard, NEERC 2006, LA 3708)需要稍稍加工的(先贪心,再确保能这样贪(可行性&;&;如果可行必定最优&;&;非证明最优性)的题)(K)
- 一套手写ajax加一般处理程序的增删查改
- .NET 4 并行(多核)编程系列之三 从Task的取消
- pig 的chararry不能用于比较的类型可以comparison operator
- ACM STUDY
- centos7 配置lamp 环境
- C++学习 —— 重新认识C++
- C#后台Post提交XML 及接收该XML的方法
- RxJS之BehaviorSubject
- AngularJS路由系列(5)-- UI-Router的路由约束、Resolve属性、路由附加数据、路由进入退出事件
- eclipse闪退解决
- 如何以编程方式打印到在 MFC 中的非默认打印机
- 爬虫框架之Scrapy——爬取某招聘信息网站