TCS codevita
Programming and Technical
Category
Raj is a newbie to the programming and while learning the programming language he came to know the following rules:
· Each program must start with '{' and end with '}'.
· Each program must contain only one main function. Main function must start with '<' and end with '>'.
· A program may or may not contain user defined function(s). There is no limitation on the number of user defined functions in the program. User defined function must start with '(' and end with ')'.
· Loops are allowed only inside the functions (this function can be either main function or user defined function(s)). Every loop must start with '{' and end with '}'.
· User defined function(s) are not allowed to be defined inside main function or other user defined function(s).
· Nested loops are allowed.
· Instructions can be anywhere inside the program.
· Number of instructions inside any user defined function must not be more than 100.
If any of the above conditions is not satisfied, then the program will generate compilation errors. Today Raj has written a few programs, but he is not sure about the correctness of the programs. Your task is to help him to find out whether his program will compile without any errors or not.
Input Format:
First line starts with T, number of test cases. Each test case will contain a single line L, where L is a program written by Raj.
Output Format:
Print "No Compilation Errors" if there are no compilation errors, else print "Compilation Errors".
Constraints:
1<=T<=100
L is a text and can be composed of any of the characters {, }, (, ), <, >and P, where P will represents the instruction.
L, comprised of characters mentioned above should be single spaced delimited.
Number of characters in the text, |L| < = 10000
Sample Input and Output
SNo. Input Output
1
3
{ < > ( P ) }
{ < { } > ( { } ) )
{ ( { } ) }
No Compilation Errors
Compilation Errors
Compilation Errors
Read Solution (Total 4)
-
- #include
#include
int end=0;
int check_function(char *str,int i,char ismain)
{
int a,b;
int inmain=0,inloop=0,ins_count=0,error=0;
if(ismain=='m')
{
a='';
}
else
{
a='(';
b=')';
}
for(i;str[i]!=b&&i - 9 years agoHelpfull: Yes(16) No(48)
- def check1(a,b,c,d,e,f,g,h,i):
j=[]
j=a[1:len(a)-1]
print(j)
l='{'
m='}'
if(a[0]=='{')and(a[-1]=='}'):
if((b==1)and(c==1))and(d < e):
if(g not in f) and (h not in f):
print("No Compilation Errors")
else:
print("Compilation Errors")
else:
print("Compilation Errors")
else:
print("Compilation Errors")
def check(a):
b=a.count('')
f=[]
i=[]
g='('
h=')'
b1=a.count(g)
c1=a.count(h)
try :
d=a.index('')
f=a[d:e+1]
check1(a,b,c,d,e,f,g,h,i)
except ValueError:
print("Compilation Errors")
def T_con(T):
s=[]
for i in range (0,T):
b=str(input())
c=b.split()
s.insert(i,c)
for j in range(0,T):
if((2*len(s[j]))=1) and (T - 3 years agoHelpfull: Yes(2) No(0)
- sample=input("")
'''condition 1: start and end with { }
condition 2: one and only main function < >
condition 3: user defined functions are denoted by ( )
condition 4: loops can be used only inside functions,denoted by { }
condition 5: user defined functions not allowed inside user defined/main function
'''
def startend(line):
if line[0]=="{" and line[-1]=="}":
return True
def countmainfun(line):
count=0
o=0
c=0
for i in range(len(line)):
if line[i]=="":
count+=1
c=i
if o2:
openloop=line.find("{",1)
closeloop=line.find("}")
openmain=line.find("")
openuser=line.find("(")
closeuser=line.find(")")
if openloopopenmain and closeloop0:
if openloop>openuser and closeloop - 3 years agoHelpfull: Yes(1) No(0)
- sample=input("")
def startend(line):
if line[0]=="{" and line[-1]=="}":
return True
def countmainfun(line):
count=0
o=0
c=0
for i in range(len(line)):
if line[i]=="":
count+=1
c=i
if o2:
openloop=line.find("{",1)
closeloop=line.find("}")
openmain=line.find("")
openuser=line.find("(")
closeuser=line.find(")")
if openloopopenmain and closeloop0:
if openloop>openuser and closeloop - 3 years agoHelpfull: Yes(1) No(1)
TCS codevita Other Question