URI 2694 Solved by C programming 2

URI 2694 Solved by C programming

URI Online Judge | 2694

Problem with the Calculator

By Neilor Tonin, URI | BrazilTimelimit: 1

Joãozinho have to help his father. One specific report are being pressed with unwished letters between the three existing numbers. You have to do a program to sum these three numbers, ignoring the letters existents. Each line have no spaces.

Input

The first line of input contains an integer N (N < 100000). Follow N lines with exacly 14 characters that must be read and the three number existing in this line must be extracted and summed.

Output

For each input, your program must print a integer representing the sum of the 3 existent numbers of that line.

Input SampleOutput Sample
3
Ab23s249ttu21
At01v021kkk12
xx14l134mjm01
293
34
149
sample

Solved by C programming


#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main()
{

   int t;
    scanf("%d",&t);
   while(t--)
  {
      char str[15],tmp1[3],tmp2[4],tmp3[3];
      int l,i,m=0,n=0,o=0,sum=0,num1=0,num2=0,num3=0;
      //gets(str);
      scanf("%s",str);
      l=strlen(str);

    for (i=0;i<l;i++)
    {
        if(i>=2 && i<=3)
        {
            tmp1[m]=str[i];
            m++;
            continue;
        }
        else if(i>=5 && i<=7)
        {
            tmp2[n]=str[i];
            n++;
            continue;
        }
        else if(i>=11 && i<=12)
        {
            tmp3[o]=str[i];
            o++;
            continue;
        }
    }
    tmp1[m]='\0';
    tmp2[n]='\0';
    tmp3[o]='\0';
    num1=atoi(tmp1);
    num2=atoi(tmp2);
    num3=atoi(tmp3);
    sum=num1+num2+num3;
    printf("%d\n",sum);

    sum=0;num1=0;num2=0;num3=0;


}



    return 0;

}