Translate

Tuesday, 20 January 2015

ABSYS spoj problem solution(Anti-Blot System)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
HII GUYS........
this is a problem of string...........this is very easy but good for beginners...........


HERE IS MY AC C++ solution is.....
IF U HAVE ANY ISSUE IN THIS U CAN ASK ME IN COMMENT........

#include<bits/stdc++.h>
using namespace std;
int main()
{
 int t;
 scanf("%d\n",&t);
 //getchar();
 while(t--)
 {
  char str1[1000],str2[1000],str3[1000];
  scanf("%s",str1);
  getchar();
  getchar();
  scanf("%s",str2);
  getchar();
  getchar();
  scanf("%s",str3);
  getchar();
 /* printf("str1=%s\n",str1);
  printf("str2=%s\n",str2);
  printf("str3=%s\n",str3);
  */
  
  
  if(strstr(str1,"machula"))
  {
   int len2=strlen(str2);
   int len3=strlen(str3);
   int num3=0;
   int num2=0,i;
   for(i=0;i<len2;i++)
   num2=10*num2+(str2[i]-'0');
   for(i=0;i<len3;i++)
   num3=10*num3+(str3[i]-'0');
   int ans=num3-num2;
   printf("%d + %s = %s\n",ans,str2,str3);
   continue;
  }
   if(strstr(str2,"machula"))
  {
   int len1=strlen(str1);
   int len3=strlen(str3);
   int num3=0;
   int num1=0,i;
   for(i=0;i<len1;i++)
   num1=10*num1+(str1[i]-'0');
   for(i=0;i<len3;i++)
   num3=10*num3+(str3[i]-'0');
   int ans=num3-num1;
   printf("%s + %d = %s\n",str1,ans,str3);
   continue;
  }
   if(strstr(str3,"machula"))
  {
   int len2=strlen(str2);
   int len1=strlen(str1);
   int num1=0;
   int num2=0,i;
   for(i=0;i<len2;i++)
   num2=10*num2+(str2[i]-'0');
   for(i=0;i<len1;i++)
   num1=10*num1+(str1[i]-'0');
   int ans=num1+num2;
   printf("%s + %s = %d\n",str1,str2,ans);
   continue;
  }
 }
 return 0;
}

No comments:

Working With Java Collections