其他分享
首页 > 其他分享> > Problem H: 小学生算术

Problem H: 小学生算术

作者:互联网

 

 

 知识点:输进去第一位是最高位,需要逆序(垃圾oj函数用不了还得自己写) ,或者从末尾处理(但是两个数可能长度不同,有点困难)

有999999 1的情况

ascII值减去48  ’0‘的值

#include<stdio.h>
#include<string.h>
void strrev1(char *y){
	char d[20]="";
	for(int x=strlen(y)-1;x>=0;x--){
		d[x]=y[strlen(y)-x-1];
	}
	strcpy(y,d);
}
int main(){
	char a[20];
	char b[20];
	char c[20];
	while(scanf("%s %s",&a,&b)!=EOF){
		int n=0,i;
		 strrev1(a);
		  strrev1(b);
		 //printf("%s %s\n",&a,&b);
		if(strlen(b)>strlen(a)){
			strcpy(c,b);
			strcpy(b,a);
			strcpy(a,c);
		}
		int alen=strlen(a);
		for(i=0;i<strlen(b);i++){
			if(a[i]+b[i]-96>=10){
				n++;
				a[i+1]+=1;
			}
		}
		for(;i<alen;i++){
			if(a[i]-48>=10){
				n++;
				a[i+1]+=1;
			}//单独处理多出来的 
		}
		printf("%d\n",n);		
	}
}

标签:20,strrev1,算术,char,int,strcpy,Problem,strlen,小学生
来源: https://blog.csdn.net/FYBGC/article/details/121438964