Counting in Lojban, an artificial language developed over
the last fourty years, is easier than in most languages
The numbers from zero to nine are:
0 no
1 pa
2 re
3 ci
4 vo
5 mk
6 xa
7 ze
8 bi
9 so
Larger numbers are created by gluing the digit togather.
For Examle 123 is pareci
Write a program that reads in a lojban string(representing
a no less than or equal to 1,000,000) and output it in
numbers.

Answers were Sorted based on User's Feedback



Counting in Lojban, an artificial language developed over the last fourty years, is easier than in..

Answer / ashwin murali

#include<iostream>
using namespace std;
#include<cstring>

int main(){
string str="parecisobixa";
int l;
l=str.length();
cout<<l<<endl;
for(int i=0;i<=l;i=i+2){
string sub=str.substr(i,2);


if(sub=="pa"){cout<<1; }
if(sub=="re"){cout<<2;}
if(sub=="ci"){cout<<3;}
if(sub=="vo"){cout<<4;}
if(sub=="mk"){cout<<5;}
if(sub=="xa"){cout<<6;}
if(sub=="ze"){cout<<7;}
if(sub=="bi"){cout<<8;}
if(sub=="so"){cout<<9;}
}

return 0;
}

Is This Answer Correct ?    7 Yes 1 No

Counting in Lojban, an artificial language developed over the last fourty years, is easier than in..

Answer / manoj pathak

#include<iostream.h>
#include<conio.h>

void main()
{
int i=0,k;
char ph,ch[10];
clrscr();
while(ph!='\r')
{
ph=getche();
ch[i]=ph;
i++;
}
cout<<endl<<endl<<endl;
for(k=0;k<i;)
{
if(ch[k]=='n')
{
if(ch[k+1]=='o')
cout<<"0";
else
{
clrscr();
cout<<"Entered String is not code" ;
break;
}
}
if(ch[k]=='p')
{
if(ch[k+1]=='a')
cout<<"1";
else
{
clrscr();
cout<<"Entered String is not code" ;
break;
}
}

if(ch[k]=='r')
{
if(ch[k+1]=='e')
cout<<"2";
else
{
clrscr();
cout<<"Entered String is not code" ;
break;
}
}

if(ch[k]=='c')
{
if(ch[k+1]=='i')
cout<<"3";
else
{
clrscr();
cout<<"Entered String is not code" ;
break;
}
}

if(ch[k]=='v')
{
if(ch[k+1]=='o')
cout<<"4";
else
{
clrscr();
cout<<"Entered String is not code" ;
break;
}
}

if(ch[k]=='m')
{
if(ch[k+1]=='k')
cout<<"5";
else
{
clrscr();
cout<<"Entered String is not code" ;
break;
}
}

if(ch[k]=='x')
{
if(ch[k+1]=='a')
cout<<"6";
else
{
clrscr();
cout<<"Entered String is not code" ;
break;
}
}

if(ch[k]=='z')
{
if(ch[k+1]=='e')
cout<<"7";
else
{
clrscr();
cout<<"Entered String is not code" ;
break;
}
}

if(ch[k]=='b')
{
if(ch[k+1]=='i')
cout<<"8";
else
{
clrscr();
cout<<"Entered String is not code" ;
break;
}
}

if(ch[k]=='s')
{
if(ch[k+1]=='o')
cout<<"9";
else
{
clrscr();
cout<<"Entered String is not code" ;
break;
}
}

k=k+2;
}
getch();
}

Is This Answer Correct ?    4 Yes 4 No

Counting in Lojban, an artificial language developed over the last fourty years, is easier than in..

Answer / iti tomar

string [] q = new string
[10];//"no","pa","re","ci","vo","mk","xa","ze","bi","so"];
q[0] = "no";
q[1] = "pa";
q[2] = "re";
q[3] = "no";
q[4] = "ci";
q[5] = "vo";
q[6] = "mk";
q[7] = "xa";
q[8] = "ze";
q[9] = "bi";
int alen = q.Length;
//q[0] = "so";
int ln;
string result= string.Empty;
int res;
string str = (string)TextBox1.Text;
ln = str.Length;
if (ln % 2 != 0)
{
Response.Write("Invalid number");
}
else
{

string r;
for (int i = 0; i <= ln-2; i = i + 2)
{
for (int ale = 0; ale < alen; ale++)

if (str.Substring(i,2) == q[ale])
{

result = result + ale.ToString();
//i++;
//i++;
}


}

TextBox2.Text = result;

}

}
}

Is This Answer Correct ?    0 Yes 2 No

Counting in Lojban, an artificial language developed over the last fourty years, is easier than in..

Answer / sudha

#include<conio.h>
#include<iostream>

int main()
{
char *q[] = {"no", "pa", "re", "ci", "vo", "mk", "xa",
"ze", "bi", "so"};
char *lojban, num[3];
int i,j,k;

cout << "\nEnter the value in lojban\n" ;
cin >> lojban;

i=0;
while(lojban[i++]);

num[2] = '\0';
cout << "The number is \n";

for(j=0; j<i-1; j=j+2)
{
k = 0;
strncpy(num, lojban+j, 2);

do
{
if (k == 11) { cout << "<Invalid Entry>";
break;}
}while(strcmp(num,q[k++]));

if (k != 11)
cout << k-1;

}

getch();
return(0);
}

Is This Answer Correct ?    1 Yes 5 No

Post New Answer

More C++ Code Interview Questions

Show by induction that 2n > n2, for all n > 4.

2 Answers   Karvy, Qatar University,


A research student is given a singly-linked list. Each node of the list has a color, which is either “Black” or “White”. He must find if there are more black nodes than white nodes, or vice versa. His advisor gives him 5,000Rs to buy a computer to do the work. He goes to the computer store and finds a slightly defective computer which costs a mere 3,000Rs. This computer has the small problem of not being able to do arithmetic. This means that he cannot use a counter to count the nodes in the list to determine the majority color. The computer is otherwise fully functional. He has the evil idea that he could buy the defective computer and somehow use it to do his work, so that he can use the rest of the money on enjoyment. Show how he can accomplish this amazing task. Write code for an algorithm called ‘findMajorityColor’ which takes a singly-linked list, L, with n nodes and returns the majority color among nodes of L. This algorithm should have the same asymptotic running time as counting the nodes (O(n)). Note: No arithmetic is allowed.

2 Answers  


Implement a command console for changing settings on a particular object. The command console should allow you to enter a string and will return the response (very similar to a terminal session). The commands are as follows: SET propertyname=newvalue will change the target object’s member named “propertyname” to have a value equal to “newvalue”. If the input value is incompatible (i.e. an int being set to a string), print out an appropriate error message. GET propertyname will print out the current value of the target object’s member named “propertyname”. GET * will print out a list of all target object members and their current values. The system should be extensible for future commands and should accept an arbitrary object, such that another developer could insert another object into the system and rely on the command console to get and set the properties correctly.

0 Answers   ABC, Guidance Software,


Write a program that takes a 3 digit number n and finds out whether the number 2^n + 1 is prime, or if it is not prime find out its factors.

2 Answers   TCS,


Coin Problem You are given 9 gold coins that look identical. One is counterfeit and weighs a bit greater than the others, but the difference is very small that only a balance scale can tell it from the real one. You have a balance scale that costs 25 USD per weighing. Give an algorithm that finds the counterfeit coin with as little weighting as possible. Of primary importance is that your algorithm is correct; of secondary importance is that your algorithm truly uses the minimum number of weightings possible. HINT: THE BEST ALGORITHM USES ONLY 2 WEIGHINGS!!!

1 Answers   Motorola, Qatar University,






1+1/2!+1/3!+...+1/n!

0 Answers  


#include<iostream.h> //main() //{ class A { friend class B; public: void read(); }; class B { public : int a,b; }; void A::read() { cout<<"welcome"; } main() { A x; B y; y.read(); } In the above program......, as B is a friend of A B can have access to all members,i cant access y.read . could you please tell me the reason and what would i code to execute this program?

2 Answers  


Faster Computers Suppose you have a computer that requires 1 minute to solve problem instances of size 1000. What instance sizes can be run in 1 minute if you buy a new computer that runs 1000 times faster than the old one, assuming the following time complexities T(n) for our algorithm? (a) T(n) = O(n). (b) T(n) = O(n3). (c) T(n) = O(10n).

1 Answers   Qatar University,


#include<stdio.h> #include<conio.h> void main() { char str[10]; int,a,x,sw=0; clrscr(); printf("Enter a string:"); gets(str); for(x=0;x<=a;a++); for(x=0;x<=a;x++) { if(str[x]==str[a-1-x]) { sw=1; } else sw=0; } if(sw==10 printf("The entered string is palindrome:"); else printf("The entered string is not a palindrome:); } getch(); } wht would be the explanation with this written code???

2 Answers  


Seat Reservation prog for the theatre. Write a function for seat allocation for the movie tickets. Total no of seats available are 200. 20 in each row. Each row is referred by the Character, "A" for the first row and 'J' for the last. And each seat in a row is represented by the no. 1-20. So seat in diffrent rows would be represented as A1,A2....;B1,B2.....;........J1,J2... Each cell in the table represent either 0 or 1. 0 rep would seat is available , 1 would represent seat is reserved. Booking should start from the last row (J) to the first row(A). At the max 20 seats can be booked at a time. if seats are available, then print all the seat nos like "B2" i.e (2 row, 3 col) otherwise Print "Seats are not available." and we must book consecutive seats only.

1 Answers   Nagarro,


write a function -oriented program that generates the Fibonacci, the current numbers of n(as input) and display them (series). In Fibonacci, the current third number is the sum of the previous number.

3 Answers  


Teta-Omeg-Big-Oh Show that f(n) = n2 + 3n3 is ;(n3).

0 Answers   Qatar University,


Categories