//1024 既然已经注意到是大整数相加了下面还用int 求和 to_string 这合适吗,不合适,数组也可以reverse 大整数相加千万不要在中途中再用整数赋值 否则大整数就白写了
#include
using namespace std;
struct bign{
int d[1000];
int len;
bign(){
memset(d,0,sizeof(d));
len=0;
}
};
/*bign change(string a){
bign c;
c.len=a.size();
for(int i=0;i>a>>m;
int flag=1;
for(int i=0;i
//1023 大整数
#include
using namespace std;
struct bign{
int d[1000];
int len;
bign(){
memset(d,0,sizeof(d));
len=0;
}
};
bign change(char a[]){
bign c;
c.len=strlen(a);
for(int i=0;i book(10),book1(10);
//int book[10];
int main(){
char _1[50];
scanf("%s",&_1);//char型%d傻啦? 1
//cin>>_1;
bign _2,_3;
_2=change(_1);
for(int i=0;i<_2.len;i++){
book[_2.d[i]]++;
}
_3=multi(_2,2);
for(int i=0;i<_3.len;i++){
book1[_3.d[i]]++;
}
if(book1==book){
printf("Yes\n");
}else {
printf("No\n");
}
for(int i=0;i<_3.len;i++){
printf("%d",_3.d[_3.len-1-i]);
}
return 0;
}
//最大公约数
#include
using namespace std;
int gcd(int a,int b){
if(b==0) return a;
else gcd(b,a%b);
}
int main(){
int _1,_2,_3;
scanf("%d%d",&_1,&_2);
_3=gcd(_1,_2);
cout<<_3;
return 0;
}
#include
using namespace std;
struct fra{
long long int up,down;
};
int gcd(int a1,int b1){
if(b1==0){
return a1;
}
else gcd(b1,a1%b1);
}
fra reduction(fra a){
if(a.down<0){
a.down=-a.down;
a.up=-a.up;
}
if(a.up==0){//==写成=于以后干脆复制吧
a.down=1;
}
if(gcd(abs(a.up),abs(a.down) )!=1){//abs忘带
int temp= gcd(abs(a.up),abs(a.down));
a.up=a.up/temp;//上面刚赋完值,下面有涉及到的要引参要的是变化前的
a.down=a.down/temp;//化简时gcd需要引参 否则上面赋值会影响下面gcd的运算
}
return a;
}
fra add(fra a,fra b){
fra c;
c.up=a.up*b.down+a.down*b.up;
c.down=a.down*b.down;
return reduction(c);
}
fra sub(fra a,fra b){
fra c;
c.up=a.up*b.down-a.down*b.up;
c.down=a.down*b.down;
return reduction(c);
}
fra multi(fra a,fra b){
fra c;
c.up=a.up*b.up;
c.down=a.down*b.down;
return reduction(c);
}
fra divide(fra a,fra b){
fra c;
c.up=a.up*b.down;
c.down=a.down*b.up;
return reduction(c);
}
void show(fra a){
if(a.down==1) printf("%lld",a.up);//= ?==
else if(a.up==0) printf("%lld",0);
else if(abs(a.up)>abs(a.down)) printf("%lld %lld/%lld",a.up/a.down,abs(a.up%a.down),a.down);
else printf("%lld/%lld",a.up,a.down);
}
int main(){
fra _1,_2;
_1.up=3;
_1.down=5;
_2.up=4;
_2.down=2;
fra _3=add(_1,_2);
show(_3);
printf("\n");
fra _4=sub(_1,_2);
show(_4);
printf("\n");
fra _5=multi(_1,_2);
show(_5);
printf("\n");
fra _6=divide(_1,_2);
show(_6);
printf("\n");
return 0;
}
//1081 双等不能写成等于 gcd有引参 reduction 3种情况 show 4种情况 一开始求和的sum 上0下1
#include
using namespace std;
int gcd(int a,int b){
if(b==0) return a;
else gcd(b,a%b);
}
struct fra{
int up,down;
};
fra reduction(fra a){
if(a.up==0){
a.down=1;
}
if(a.down<0){
a.up=-a.up;
a.down=-a.down;
}
if(gcd(abs(a.up),abs(a.down))!=1){
int temp=gcd(abs(a.up),abs(a.down));
a.up=a.up/temp;
a.down=a.down/temp;
}
return a;
}
fra add(fra a,fra b){
fra c;
c.up=a.up*b.down+a.down*b.up;
c.down=a.down*b.down;
return reduction(c);
}
void show(fra a){
if(a.up==0) printf("%d",0);
else if(a.down==1) printf("%d",a.up);
else if(abs(a.up>abs(a.down))){
printf("%d %d/%d",a.up/a.down,abs(a.up)%a.down,a.down);
}
else printf("%d/%d",a.up,a.down);
}
int main(){
int n;
scanf("%d",&n);
fra sum,_1;
sum.up=0;
sum.down=1;
for(int i=0;i
3道
总结
1024大整数相加 整体与结构不统一 虽然写了大整数但是 下面用了to_string 和int变量去赋值大整数导致实际上没用上大整数的错误 要用定义的数组 reverse也是要要弄那个数组
分数 四则运算 注意化简的三条规则 输出的四条 ==双等判断 这些小细节