-
Notifications
You must be signed in to change notification settings - Fork 16
/
Ali and helping innocent people
67 lines (54 loc) · 1.8 KB
/
Ali and helping innocent people
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
/*
Arpasland has surrounded by attackers. A truck enters the city. The driver claims the load is food and medicine from Iranians. Ali is one of the soldiers in Arpasland. He doubts about the truck, maybe it's from the siege. He knows that a tag is valid if the sum of every two consecutive digits of it is even and its letter is not a vowel. Determine if the tag of the truck is valid or not.
We consider the letters "A","E","I","O","U","Y" to be vowels for this problem.
Input Format
The first line contains a string of length 9. The format is "DDXDDD-DD", where D stands for a digit (non zero) and X is an uppercase english letter.
Output Format
Print "valid" (without quotes) if the tag is valid, print "invalid" otherwise (without quotes)
SAMPLE INPUT
12X345-67
SAMPLE OUTPUT
invalid
*/
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s; int i,flag=0;
for(i=0;i<8;i++)
{
if(i==2)
{
if(isalpha(s[i]))
{
if(s[i] == 'A' || s[i] == 'E' || s[i] == 'I' || s[i]== 'O' || s[i] == 'U' || s[i] == 'Y')
{
flag=1;
break;
}
}
else
{
flag=1;
break;
}
}
if(i==6 && s[i]!='-')
{
flag=1;
break;
}
if(isdigit(s[i]) && isdigit(s[i+1]))
{
int sum=(int)s[i]+(int)s[i+1];
if(sum%2 !=0)
{
flag=1;
break;
}
}
}
if(flag==1) cout<<"invalid\n";
else cout<<"valid\n";
}