Athena Health Interview Question
Applications DevelopersCountry: India
Interview Type: In-Person
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
using namespace std;
int main() {
char str[90] =
"my brother is taller than me@1233334. I always a short man,but smart than him";
char find = 'e';
int findCount = 0, sentenceCount = 0, doubleCount = 0, wordCount = 0,
intCount = 0, wordLength = 0, maxLength = 0;
char lastChar = '\0';
char* iterator = str;
bool sentenceEnd = true, wordEnd = true;
char word[20];
string maxWord = "";
vector<char> noSpaceString ;
memset(word,'\0',20);
for (int i = 0; *iterator != '\0'; ++i, ++iterator) {
if (*iterator == find) {
++findCount;
}
if (sentenceEnd == true) {
++sentenceCount;
sentenceEnd = false;
}
if (wordEnd == true && isalpha((int) *iterator)) {
++wordCount;
wordEnd = false;
}
if (*iterator == ' ' || *iterator == ',' || *iterator == '.') {
wordEnd = true;
}
if (*iterator == '.') {
sentenceEnd = true;
}
if (isdigit((int(*iterator)))) {
++intCount;
}
if (*iterator == lastChar) {
++doubleCount;
lastChar = '\0';
} else
lastChar = *iterator;
if (isalpha((int) *iterator)) {
++wordLength;
word[wordLength-1] = *iterator;
} else {
maxLength = maxLength > wordLength ? maxLength : wordLength;
maxWord = maxLength == wordLength ? word : maxWord;
wordLength = 0;
memset(word,'\0',20);
}
if (*iterator != ' ')
noSpaceString.push_back(*iterator);
}
cout << "Number of integers: " << intCount << endl;
cout << "Number of doubles: " << doubleCount << endl;
cout << "Number of words: " << wordCount << endl;
cout << "Number of sentences: " << sentenceCount << endl;
cout << "Number of " << find << "(s): " << findCount << endl;
cout << "Biggest word: " << maxWord << endl;
cout << "Space-less String: ";
for (vector<char>::iterator it = noSpaceString.begin(); it!= noSpaceString.end(); ++it)
cout << *it;
cout << endl << "Actual String: " << str << endl;
return 0;
}
{
package coding;
//import java.util.Scanner;
public class DealingWithString {
public static void main(String args[]){
String text= "my brother is taller than me @1233334 . I always a short man , but smatter than him .";
String word[]=text.split(" ");
int max=0,count=0;
String maxStr="";
//Removing whitespaces
System.out.println("Text without space is ");
for(int i=0;i<word.length;i++)
{System.out.print(word[i]);
}
System.out.print("\n");
//Largest string
for(int i=0;i<word.length;i++)
{
if(max < word[i].length())
{
max=word[i].length();
maxStr=word[i];
}
}
System.out.println("The largest word is "+maxStr);
//Finding numbers of e letters in the given text
for(int i=0;i<text.length();i++){
if(text.charAt(i)=='e'){
count++;
}
}
System.out.println("Numbers of e in the text are: "+count);
//Finding number of double
int doubleCount=0;
for(int i=0;i<text.length()-1;i++){
char c=text.charAt(i+1);
if(text.charAt(i)==c){
doubleCount++;
}
}
System.out.println("Numbers of doubles in the text are: "+doubleCount);
//Finding number of integers
int intCount=0;
for(int j=0;j<text.length();j++){
if((text.charAt(j)>='0' && text.charAt(j)<='9')){
intCount++;
}
}
System.out.println("Numbers of integers in the text are: "+intCount);
//Finding number of words
System.out.println("Number of words in the string are :" +(word.length-3));
//Finding number of sentence
int sencount=0;
for(int i=0;i<text.length();i++){
if(text.charAt(i)=='.'){
sencount++;
}
}
System.out.println("Number of sentence is"+(sencount));
}
}
}
package com.lmali;
public class QuestionPaper {
public static void main(String args[]){
String s="my brother is taller than me @1233334 . I always a short man , but smatter than him .";
String s1=s.replaceAll(" ", "");
System.out.println("String without space: "+s1);
String[] stk=s.split(" ");
int len=0;
int index=0;
for(int i=0;i<stk.length;i++){
int stlen=stk[i].length();
if(stlen>len){
len=stlen;
index=i;
}
}
System.out.println("Longest String is :"+stk[index]);
int count=0;
for(int i=0;i<s.length();i++){
if('e'==s.charAt(i)){
count++;
}
}
System.out.println("Number of e cahracter is:"+count);
int cntDigit=0;
for(int i=0;i<s.length();i++){
if(((int)s.charAt(i)>=48 && (int)s.charAt(i)<=57)){
cntDigit++;
}
}
System.out.println("Number of Integer in string:"+cntDigit);
int wordcnt=0;
for(int i=0;i<stk.length;i++){
if(stk[i].length()==1 && ((int)stk[i].charAt(0)>=32&&(int)stk[i].charAt(0)<=47)){
}
else{
wordcnt++;
}
}
System.out.println("Number of Word in String is"+wordcnt);
String[] st=s.split("\\.");
System.out.println("Number of Sentence :"+st.length);
int doublecnt=0;
for(int i=0;i<s.length()-1;i++){
if(s.charAt(i+1)==s.charAt(i)){
doublecnt++;
}
}
System.out.println("Doubles count:"+doublecnt);
}
}
package com.lmali;
public class QuestionPaper {
public static void main(String args[]){
String s="my brother is taller than me @1233334 . I always a short man , but smatter than him .";
String s1=s.replaceAll(" ", "");
System.out.println("String without space: "+s1);
String[] stk=s.split(" ");
int len=0;
int index=0;
for(int i=0;i<stk.length;i++){
int stlen=stk[i].length();
if(stlen>len){
len=stlen;
index=i;
}
}
System.out.println("Longest String is :"+stk[index]);
int count=0;
for(int i=0;i<s.length();i++){
if('e'==s.charAt(i)){
count++;
}
}
System.out.println("Number of e cahracter is:"+count);
int cntDigit=0;
for(int i=0;i<s.length();i++){
if(((int)s.charAt(i)>=48 && (int)s.charAt(i)<=57)){
cntDigit++;
}
}
System.out.println("Number of Integer in string:"+cntDigit);
int wordcnt=0;
for(int i=0;i<stk.length;i++){
if(stk[i].length()==1 && ((int)stk[i].charAt(0)>=32&&(int)stk[i].charAt(0)<=47)){
}
else{
wordcnt++;
}
}
System.out.println("Number of Word in String is"+wordcnt);
String[] st=s.split("\\.");
System.out.println("Number of Sentence :"+st.length);
int doublecnt=0;
for(int i=0;i<s.length()-1;i++){
if(s.charAt(i+1)==s.charAt(i)){
doublecnt++;
}
}
System.out.println("Doubles count:"+doublecnt);
}
}
import java.util.StringTokenizer;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
String str = "All the best friends. You could do it by yourself!!!";
StringTokenizer arr = new StringTokenizer(str," ");
StringTokenizer sentence = new StringTokenizer(str,".");
StringBuffer str1 = new StringBuffer();
String longestStr = "";
long ecount = str.toLowerCase().chars().filter(num -> num == 'e').count();
long ncount = str.toLowerCase().chars().filter(num -> Character.isDigit(num)).count();
int wcount = arr.countTokens();
int scount = sentence.countTokens();
while (arr.hasMoreElements()) {
String currStr = arr.nextToken();
str1.append(currStr);
if(currStr.length()>longestStr.length()){
longestStr = currStr;
}
}
System.out.println(str1);
System.out.println(longestStr);
System.out.println(ecount);
System.out.println(ncount);
System.out.println(wcount);
System.out.println(scount);
}
}
import java.util.StringTokenizer;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
String str = "All the best friends. You could do it by yourself!!!";
StringTokenizer arr = new StringTokenizer(str," ");
StringTokenizer sentence = new StringTokenizer(str,".");
StringBuffer str1 = new StringBuffer();
String longestStr = "";
long ecount = str.toLowerCase().chars().filter(num -> num == 'e').count();
long ncount = str.toLowerCase().chars().filter(num -> Character.isDigit(num)).count();
int wcount = arr.countTokens();
int scount = sentence.countTokens();
while (arr.hasMoreElements()) {
String currStr = arr.nextToken();
str1.append(currStr);
if(currStr.length()>longestStr.length()){
longestStr = currStr;
}
}
System.out.println(str1);
System.out.println(longestStr);
System.out.println(ecount);
System.out.println(ncount);
System.out.println(wcount);
System.out.println(scount);
}
}
import java.util.StringTokenizer;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
String str = "All the best friends. You could do it by yourself!!!";
StringTokenizer arr = new StringTokenizer(str," ");
StringTokenizer sentence = new StringTokenizer(str,".");
StringBuffer str1 = new StringBuffer();
String longestStr = "";
long ecount = str.toLowerCase().chars().filter(num -> num == 'e').count();
long ncount = str.toLowerCase().chars().filter(num -> Character.isDigit(num)).count();
int wcount = arr.countTokens();
int scount = sentence.countTokens();
while (arr.hasMoreElements()) {
String currStr = arr.nextToken();
str1.append(currStr);
if(currStr.length()>longestStr.length()){
longestStr = currStr;
}
}
System.out.println(str1);
System.out.println(longestStr);
System.out.println(ecount);
System.out.println(ncount);
System.out.println(wcount);
System.out.println(scount);
}
}
Static problem (the way you posed it).
- S O U N D W A V E October 15, 2013So, PRINT(" < pre process the answers and put them here> ");
?