C语言 输出超长的数

C语言 输出超长的数,第1张

用字符串呀。static char s[10000]; int i,j,t,L;

输入后,L = strlen(s); 然后对 一个一个字符作排队。

for (i=0;i<L-1;i++) for (j=i+1;j<L;j++) {

if (s[i]<s[j]) { t=s[i];s[i]=s[j];s[j]=t;};

处理完了打印出来 printf("%s",s);

}

很久以前写的,不过实现的是 有符号的 加减运算,没乘除 头文件 :myinth --------------------------- #ifndef _MYINT_H #define _MYINT_H #include <iostream> #include <string> using namespace std; const int MAX=20; class MyInt { private: int arry[MAX]; int plus; int size; protected: int bigger(const MyInt & lhs) { if(size> lhssize) return 1; else if(size <lhssize) return 0; //lhs bigger else if(size=lhssize) { for(int i=size-1;i> =0;i--) { if(arry[i]> lhsarry[i]) return 1; else if(arry[i] <lhsarry[i]) return 0; } } return 0; } void add(const MyInt &lhs,int pp) { int pp_plus=lhsplus; if(pp==1) pp_plus=(pp_plus+1)%2; int temp=0; //----------------- if(plus==0&&pp_plus==0) { for(int i=0;i <MAX;i++) { temp=arry[i]+lhsarry[i]; if(temp> 9) { temp=temp-10; arry[i+1]=arry[i+1]+1; } arry[i]=temp; } } //-------------------- if(plus==0&&pp_plus==1) { if(bigger(lhs)==1) { for(int i=0;i <MAX;i++) { temp=arry[i]-lhsarry[i]; if(temp <0) { temp=temp+10; arry[i+1]=arry[i+1]-1; } arry[i]=temp; } } else { int swap[MAX]; for(int i=0;i <MAX;i++) swap[i]=arry[i]; for(i=0;i <MAX;i++) arry[i]=lhsarry[i]; for( i=0;i <MAX;i++) { temp=arry[i]-swap[i]; if(temp <0) { temp=temp+10; arry[i+1]=arry[i+1]-1; } arry[i]=temp; } } } //------------------------- if(plus==1&&pp_plus==1) { for(int i=0;i <MAX;i++) { temp=arry[i]+lhsarry[i]; if(temp> 9) { temp=temp-10; arry[i+1]=arry[i+1]+1; } arry[i]=temp; } } //------------------- if(plus==1&&pp_plus==0) { if(bigger(lhs)==1) { for(int i=0;i <MAX;i++) { temp=arry[i]-lhsarry[i]; if(temp <0) { temp=temp+10; arry[i+1]=arry[i+1]-1; } arry[i]=temp; } } else { int swap[MAX]; for(int i=0;i <MAX;i++) swap[i]=arry[i]; for(i=0;i <MAX;i++) arry[i]=lhsarry[i]; for( i=0;i <MAX;i++) { temp=arry[i]-swap[i]; if(temp <0) { temp=temp+10; arry[i+1]=arry[i+1]-1; } arry[i]=temp; } } } } public: MyInt() : plus(0),size(0) { for(int i=0;i <MAX;i++) arry[i]=0; } MyInt(string str) { int temp=0; for(int i=0;i <MAX;i++) arry[i]=0; if(str[0]== '- ') { plus=1; size=strsize()-1; for(i=strsize()-1;i> 0;i--) { temp=int(str[i])-48; arry[size-i]=temp; } } else { plus=0; size=strsize(); for(i=strsize()-1;i> =0;i--) { temp=int(str[i])-48; arry[size-1-i]=temp; } } } void operator =(const MyInt &lhs) { plus=lhsplus; size=lhssize; for(int i=0;i <MAX;i++) { arry[i]=0; arry[i]=lhsarry[i]; } } void operator +=( const MyInt &lhs) { add(lhs,0); } void operator -=(const MyInt &lhs) { add(lhs,1); } void display() { if(plus==1) cout < < "- "; int flag=0; for (int i=MAX-1;i> =0;i--) { if(arry[i]!=0||flag==1) { flag=1; if(flag==1) cout < <arry[i]; } } } }; #endif //---------- 头文件 complexh #ifndef _COMPLEX_H #define _COMPLEX_H #include "myinth " class ComplexInt { private: MyInt real; MyInt unreal; public: ComplexInt() : real( "0 "),unreal( "0 "){} ComplexInt(string r,string ur) :real(r),unreal(ur) {} ComplexInt(string r) :real(r),unreal( "0 ") {} void operator +=(const ComplexInt & lhs) { real+=lhsreal; unreal+=lhsunreal; } void operator -=(const ComplexInt & lhs) { real-=lhsreal; unreal-=lhsunreal; } void operator =(const ComplexInt & lhs) { real=lhsreal; unreal=lhsunreal; } void display() { realdisplay(); cout < < "+ "; unrealdisplay(); cout < < "i "; } }; #endif 主函数:maincpp #include "complexh " #include "myinth " void Display(MyInt myint) { cout < < "This is MyInt::Display, the result is: "; myintdisplay(); cout < <endl; } void Display(ComplexInt complex ) { cout < < "This is ComplexInt::Display, the result is: "; complexdisplay(); cout < <endl; } void main(int argc, char argv[]) { MyInt iM( "1234567890123 "); // 整数对象初始化 MyInt iN( "-4445555544444 "); MyInt iResult1; iResult1 = iM; iResult1 += iN; // 整数加法 *** 作 MyInt iResult2 = iM; iResult2 -= iN; // 整数减法 *** 作 // 结果输出 Display(iResult1); // iResult1: -1976419764198 Display(iResult2); // iResult2: 4445555544444 // 实部: 1234567890123;虚部: 4445555544444 ComplexInt ciM( "1234567890123 ", "4445555544444 "); // 复数对象初始化 // 实部: -4445555544444;虚部: 0 ComplexInt ciN( "-4445555544444 "); // 复数对象初始化 ComplexInt ciResult1 = ciM; ComplexInt ciResult2 = ciM; ciResult1 += ciN; // 复数加法 *** 作 ciResult2 -= ciN; // 复数减法 *** 作 // 结果输出 Display(ciResult1); Display(ciResult2); }

机动车载物不得超过机动车行驶证上核定的载质量,装载长度、宽度不得超出车厢,并应当遵守下列规定:

一、重型、中型载货汽车,半挂车载物,高度从地面起不得超过4米,载运集装箱的车辆不得超过42米;

二、其他载货的机动车载物,高度从地面起不得超过25米;

三、摩托车载物,高度从地面起不得超过15米,长度不得超出车身02米。两轮摩托车载物宽度左右各不得超出车把015米;三轮摩托车载物宽度不得超过车身。

载客汽车除车身外部的行李架和内置的行李箱外,不得载货。载客汽车行李架载货,从车顶起高度不得超过05米,从地面起高度不得超过4米。

扩展资料

《道路交通安全违法行为处理程序规定》中规定:

第九条 交通警察调查违法行为时,应当查验机动车驾驶证、行驶证、机动车号牌、检验合格标志、保险标志等牌证以及机动车和驾驶人违法信息。对运载爆炸物品、易燃易爆化学物品以及剧毒、放射性等危险物品车辆驾驶人违法行为调查的,还应当查验其他相关证件及信息。

第二十七条   对公路客运车辆载客超过核定乘员、货运机动车超过核定载质量的,公安机关交通管理部门应当按照下列规定消除违法状态:

(一)违法行为人可以自行消除违法状态的,应当在公安机关交通管理部门的监督下,自行将超载的乘车人转运、将超载的货物卸载;

(二)违法行为人无法自行消除违法状态的,对超载的乘车人,公安机关交通管理部门应当及时通知有关部门联系转运;对超载的货物,应当在指定的场地卸载,并由违法行为人与指定场地的保管方签订卸载货物的保管合同。

消除违法状态的费用由违法行为人承担。违法状态消除后,应当立即退还被扣留的机动车。

参考资料来源:北京市公安局公安交通管理局-中华人民共和国道路交通安全法实施条例(第五十四条)

“货车的三超证(超长、超高、超宽)”其实是指:机动车运载超限不可解体物品许可,应前往当地公安机关交通管理部门申请许可。

镇江市为例:办理材料需要行驶证复印件、反映物体形状和承运车辆照片、三超通行证申请表、押运人员名单、提供货物提送货单,不可解体的货物名称及超长、超宽、超高的数据。办理地点:镇江市九华山路6号镇江市公安局交通警察支队、镇江市冠城路8号镇江市政务服务中心公安窗口。

以上海市为例:《上海市公安局机动车超载许可证》准予批准的条件包括申请手续齐备,相关材料有效;承运单位、车辆符合所运载超限不可解体物品相应的资质条件;申请运输线路的道路条件具备运载超限不可解体物品的运输车辆通行;能确保安全通行的。

扩展资料:

相关法律法规依据:

法律《中华人民共和国道路交通安全法》

第四十八条第一款 机动车载物应当符合核定的载质量,严禁超载;载物的长,宽,高不得违反装载要求,不得遗洒,飘散载运物。

第二款 机动车载运超限的不何解体的物品,影响交通安全的,应当按照公安机关交通管理部门指定的时间,路线,速度行驶,悬挂明显标志。在公路上运载超限的不可解体的物品,并应当依照公路法的规定执行。

行政法规《城市道路管理条例》(国务院令第198号)

第二十八条 履带车,铁轮车或者超重,超高,超长车辆需要在城市道路上行驶的,事先须征得市政工程行政主管部门同意,并按照公安交通管理部门指定的时间路线行驶。

参考资料来源:国家政务服务平台-机动车运载超限的不可解体物品运输审批

参考资料来源:上海市虹口区人民政府-机动车运载超限不可解体物品许可办事指南

既然楼主要求用C语言,那就用经典的C指针吧

#include <stdioh>

#include <stringh>

#include <stdlibh>

char BigIntAdd(char x,char y,char z)

{

int lenx=strlen(x);

int leny=strlen(y);

char pmax=x,pmin=y,pz=z,p1,p2,t;

int i,lenmax=lenx,lenmin=leny;

if (lenx < leny)

{

pmax=y;

pmin=x;

lenmax=leny;

lenmin=lenx;

}

p1=pmax+lenmax-1;

p2=pmin+lenmin-1;

while(p2>=pmin)

{

pz = p1 + p2 -'0';

if (pz>z && (pz-1)>='0'+10)

{

(pz-1)-=10;

pz+=1;

}

p1--;p2--;pz++;

}

for(i=0;i<lenmax-lenmin;i++)

{

pz=p1;

if (pz>z && (pz-1)>='0'+10)

{

(pz-1)-=10;

pz+=1;

}

pz++;p1--;

}

pz--;

if (pz>='0'+10)

{

(pz++)-=10;

pz='1';

}

for(p1=z;p1<pz;p1++,pz--)

{

t=p1;p1=pz;pz=t;

}

return z;

}

void main()

{

system("color 1e");

char x[102410]={0},y[1024]={0},z[1024]={0};

printf("Enter Large Integers 1:\n");

scanf("%s",x);

printf("Enter Large Integers 2:\n");

scanf("%s",y);

BigIntAdd(x,y,z);

printf("\n\nBigInt Add:\n%s\n\t+\n%s\n\t=\n%s\n",x,y,z);

system("pause");

}

主要想法是,判断两个数字的长短,找出最短的数字,从个位数开始与另一个数的相应位进行相加(注意判断向上进位),将结果逐个保存在结果字符串中。最后将长的那个数字 剩下的部分直接 放在结果字符串中,然后将结果字符串反转,得到结果

以上就是关于C语言 输出超长的数全部的内容,包括:C语言 输出超长的数、使用C++编写一个程序实现无符号超长整数的算术运算(加、减、乘、除)发送至[email protected]、汽车载货超高超长怎么规定的等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/9859799.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-02
下一篇 2023-05-02

发表评论

登录后才能评论

评论列表(0条)

保存