Home > Back-end >  Save the children.
Save the children.

Time:11-24

A great god help me,
Although this is very simple, but I really can't,

CodePudding user response:

For your reference

 # include & lt; stdio.h> 
#include
#include
#include

Int main ()
{
Char s [100];
Char * p=s;//pointer manipulation since pay according to the
Char TMP [100]={0};//is used to store every integer division
int sum=0;
Int pos1=0, pos2=0, pos3=0, pos4=0;//four variables of dividing point
Gets (s);
for(int i=0; iIf (isdigit (s [I]) | | s [I]=='-') {
Pos1 + +;//find the end of the first integer position, namely the length of the first integer
}
The else
{
break;
}
}
Strncpy (TMP, p, pos1);//fill the integer to a string array of TMP
The sum +=atoi (TMP);//will step on a string into an integer
Memset (TMP, 0, sizeof (TMP));//to save temporary array to empty the next integer
P +=pos1;//pointer to the starting point of a variable, is easy to copy

Pos2=pos1 + 5;//find the end position of the string
P +=pos2 - pos1;//pointer to the starting point of a variable, is easy to copy
for(int i=0; iIf (s [I]! {
=', ')Pos3 + +;//find the end position of the second integer
}
The else
{
break;
}
}
Pos4=strlen (s) - pos3;//the length of the third integer
Strncpy (TMP, p, pos3 - pos2);//pos3 - pos2 is the length of the third integer oh
The sum +=atoi (TMP);
Memset (TMP, 0, sizeof (TMP));
P +=pos3 - pos2;
Strncpy (TMP, p + 1, pos4);//p + 1 is ruled out here last comma in front of an integer
The sum +=atoi (TMP);
Memset (TMP, 0, sizeof (TMP));

Printf (" % d \ n ", sum);
return 0;
}
  • Related