æè·¯ï¼
1.è¾å
¥xxxx+xxxxxxï¼å·²â+âåå²æ两个å串ã
2.éåºä¸¤ä¸ªå串ï¼æ«ä½åæé¦ä½å¯¹é½ï¼æä½ç¸å ï¼å¤§äº10åååä½è¿ä¸ã
3.éè¦èèå°ä¸¤ä¸ªæ°é¿åº¦ä¸åçæ
åµã
4.åææåçç»æéåºè¾åºï¼å°±å¾å°äºæç»æ£åç¸å çç»æã
æè·¯å®ç°ä»£ç å¦ä¸(å¨vc6.0ä¸ç¼è¯éè¿)ï¼
#include <stdio.h>
#include <string.h>
void reverse(char *s,int len);
char * addLargeNumber(char *s1,char *s2);
int main(int argc, char const *argv[])
{
char str[100];
int len[10];//æªåçæ¯ä¸ªå串çé¿åº¦
scanf("%s",str);
char *sep = "+-*/";
char *p = strtok(str,sep);
char *s = p;
char *k = p;
len[0] = strlen(p);
reverse(p, len[0]);
puts(p);
while(1)
{
s = strtok(NULL, sep);
if (s == NULL)
{
break;
}
len[1] = strlen(s);
reverse(s,len[1]);
puts(s);
k = s;//
}
printf("access to addLargeNumber\n");
p = addLargeNumber(p,k);
len[2] = strlen(p);
reverse(p,len[2]);
puts(p);
return 0;
}
//å转ä¸ä¸ªå符串
void reverse(char *s,int len)
{
char temp;
int i;
for(i = 0;i<len/2;i++)
{
temp = s[i];
s[i] = s[len-1-i];
s[len-1-i] = temp;
}
}
//æ¥æ¶ä¸¤ä¸ªå符串ï¼æé¿åº¦å°çå å°é¿åº¦å¤§ç串ä¸ï¼è¿åç¸å åç串
char * addLargeNumber(char *s1,char *s2)
{
char *p = s1;
char *q = s2;
char k;
int i;
printf("å串1çé¿åº¦=%lu å串2çé¿åº¦=%lu\n", strlen(p),strlen(q));
int len = strlen(q);
//ç¡®ä¿pæåé¿åº¦è¾é¿ç串ãç¡®ä¿lençå¼ä¸ºè¾å°ç串çé¿åº¦ã
if (strlen(s1)<strlen(s2))
{
len = strlen(p);
q = s2;
p = s1;
}
int difflen = strlen(p)-strlen(q);//两个å串é¿åº¦çå·®å¼ã
//printf("len = %d difflen = %d\n",len ,difflen);
for (i = 0; i <len; ++i)
{
int a = p[i] + q[i] -96;
//printf("a = %d\n", a);
if (a>=10)
{
k = a -10+ 48;
p[i+1] += 1;
}
else
{
k = a + 48;
}
//printf("k = %c\n", k);
p[i] = k;
printf("p[%d] = %c\n", i,p[i]);
}
//解å³è¾é¿ä¸²åä¸ä½å¦æ被è¿ä½çæ
åµãä¾å¦:1379+128(å设两个已éåºç串)æè
15999+148
for(i = 0;i<difflen;i++)
{
if (p[len+i] == 58)
{
p[len+i] -= 10;
if (i == difflen-1)
{//å½iæåæåä¸ä¸ªæææ°åæ¶ï¼å¹¶ä¸å½åä½æ¯â:âï¼åå°å
¶åä¸ä½èµä¸ºç»æ符
p[len+i+1] = 49;//è¿ç§æ¯èµå¼ç¬¦å·ï¼æ¯å°'1'èµç»p[i]ã对æ¯ä¸é¢çè¿ç®ç¬¦
p[len+difflen+1] = 0;
}
else
{
p[len+i+1] += 1;//è¿ç§æ¯è¿ç®ç¬¦ï¼æ¯å°p[i]çASCIIç å 1.
}
printf("p[%d] = %c\n",len+i,p[len+i] );
}
else
{
break;
}
}
printf("ç¸å ä¹åç串é¿åº¦= %lu\n", strlen(p));
puts(p);
return p;
}