Epic Systems Interview Question
Software DevelopersCountry: United States
std::string NextInSeries(std::string cur)
{
std::string rval;
int j;
for (int i = 0; i < cur.size(); i = j)
{
for(j = i+1; cur[j] == cur[i]; j++);
rval += '0'+j-i;
rval += cur[i];
}
return rval;
}
void main()
{
while (1)
{
std::string cur; std::cin >> cur;
for (int i = 0; i < 10; i++)
{
cur = NextInSeries(cur);
std::cout << cur << "\n";
}
}
}
public static void PrintSeries(int n)
{
string N = n.ToString();
for(int i = 0; i < 10; i++)
{
char prev = N[0];
int count = 1;
StringBuilder sb = new StringBuilder();
for(int i = 1; i < N.Length; i++)
{
char c = N[i]
if( c != prev)
{
sb.Append(count.ToString() + prev);
prev = c;
count = 1;
}
else
{
count++;
}
}
// Doing final append of the last values
sb.Append(count.ToString + prev);
Console.WriteLine(sb.ToString());
}
}
C# code:
class Program
{
static void Main(string[] args)
{
Console.WriteLine("give a number");
string num=Console.ReadLine();
PrintSeries(num);
Console.ReadKey();
}
public static void PrintSeries(string num)
{
string concatString = num;
while(concatString.Length <10)
{
concatString = ContinousSeries(concatString);
Console.WriteLine(concatString);
}
}
public static string ContinousSeries(string num)
{
string concatString=null;
int count=1;
int i;
if (num.Length == 1)
{
concatString = count + num;
}
else
{
for (i = 0; i < num.Length - 1; i++)
{
if (num[i] == num[i + 1])
{
count++;
}
else
{
concatString = concatString + count.ToString();
concatString = concatString + num[i].ToString();
count = 1;
}
if ((i + 1) == num.Length - 1)
{
concatString = concatString + count.ToString();
concatString = concatString + num[i + 1].ToString();
}
}
}
return concatString;
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("give a number");
string num=Console.ReadLine();
PrintSeries(num);
Console.ReadKey();
}
public static void PrintSeries(string num)
{
string concatString = num;
while(concatString.Length <10)
{
concatString = ContinousSeries(concatString);
Console.WriteLine(concatString);
}
}
public static string ContinousSeries(string num)
{
string concatString=null;
int count=1;
int i;
if (num.Length == 1)
{
concatString = count + num;
}
else
{
for (i = 0; i < num.Length - 1; i++)
{
if (num[i] == num[i + 1])
{
count++;
}
else
{
concatString = concatString + count.ToString();
concatString = concatString + num[i].ToString();
count = 1;
}
if ((i + 1) == num.Length - 1)
{
concatString = concatString + count.ToString();
concatString = concatString + num[i + 1].ToString();
}
}
}
return concatString;
}
}}
package com.company.epic;
public class Question3 {
static String next(String n) {
String nStringFormat = n + "";
char previousDigit = nStringFormat.charAt(0), currentDigit = ' ';
int noOfOccurences = 1;
String nextNumber = "";
for (int last = 1; last < nStringFormat.length(); last++) {
currentDigit = nStringFormat.charAt(last);
if (currentDigit != previousDigit) {
nextNumber = nextNumber + noOfOccurences + "" + previousDigit;
previousDigit = currentDigit;
noOfOccurences = 1;
} else {
noOfOccurences++;
}
}
nextNumber = nextNumber + noOfOccurences + previousDigit;
return nextNumber;
}
public static void main(String[] args) {
String nextNumber = "22111";
for (int i = 0; i < 10; i++) {
System.out.print(nextNumber + " ");
nextNumber = next(nextNumber);
}
}
}
public class CountSeries {
public static void main(String[] args) {
print("12");
}
public static void print(String initialNum) {
int i = 0;
StringBuffer str = new StringBuffer(initialNum);
System.out.println(str);
String temp = initialNum;
while (i < 10) {
temp = str.toString().trim();
str = new StringBuffer();
int curr = 0;
int previous = Integer.parseInt(Character.toString(temp.charAt(0)));
int count = 1;
for (int x = 1; x < temp.length(); x++) {
curr = Integer.parseInt(Character.toString(temp.charAt(x)));
if (curr != 0) {
if (curr == previous) {
count++;
} else {
str.append(count).append(previous);
count = 1;
}
previous = curr;
}
}
str.append(count).append(previous);
System.out.println(str);
i++;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace series
{
class Program
{
static void Main(string[] args)
{
Int64 num = 12;
string strOut = num.ToString();
for(int i = 0; i < 10; i++)
{
Console.Write(strOut + " ");
strOut = PrintSeries(num);
Int64.TryParse(strOut,out num);
}
//PrintSeries(1);
Console.Read();
}
static string PrintSeries(Int64 num)
{
string temp, strOut = string.Empty;
int count = 1;
temp = num.ToString();
char prev = temp[0];
int length = temp.Length;
for (int i = 1; i < length; i++)
{
if (temp[i] == prev)
{
count++;
}
else if (temp[i] != prev)
{
strOut = strOut + count.ToString() + prev.ToString();
count = 1;
prev = temp[i];
}
if (i + 1 == length)
{
strOut = strOut + count.ToString() + prev.ToString();
count = 1;
prev = temp[i];
}
}
if (length == 1)
{
strOut = count.ToString() + temp;
}
return strOut;
}
}
}
package epic;
public class LookSay {
public static void main(String arg[]) {
int num = 12;
printSeries(new Integer(num).toString(), 1);
}
static void printSeries(String num, int limit) {
if(limit == 10) {
System.exit(0);
}
if(limit == 1) {
System.out.print(num);
}
StringBuffer newNumStr = new StringBuffer("");
for(int i=0; i<num.length();) {
int count = 1;
char current = num.charAt(i);
i++;
while (i < num.length() && current == num.charAt(i)) {
i++;
count++;
}
newNumStr.append(count).append(current);
}
System.out.print(" " + newNumStr);
printSeries(newNumStr.toString(), ++limit);
}
}
public class P24 {
private static void print(String start, int n) {
for (int i = 2; i < n; i++) {
StringBuilder newString = new StringBuilder();
int j = 0;
while (j < start.length()) {
char c = start.charAt(j);
int count = 0;
while (j < start.length() && start.charAt(j) == c) {
count++;
j++;
}
newString.append(count + "" + c);
}
System.out.println(newString);
start = newString.toString();
}
}
public static void main(String[] args) {
print("1", 10);
}
}
package com.company.epic;
public class Question3 {
static String next(String n) {
String nStringFormat = n + "";
char previousDigit = nStringFormat.charAt(0), currentDigit = ' ';
int noOfOccurences = 1;
String nextNumber = "";
for (int last = 1; last < nStringFormat.length(); last++) {
currentDigit = nStringFormat.charAt(last);
if (currentDigit != previousDigit) {
nextNumber = nextNumber + noOfOccurences + "" + previousDigit;
previousDigit = currentDigit;
noOfOccurences = 1;
} else {
noOfOccurences++;
}
}
nextNumber = nextNumber + noOfOccurences + previousDigit;
return nextNumber;
}
public static void main(String[] args) {
String nextNumber = "22111";
for (int i = 0; i < 10; i++) {
System.out.print(nextNumber + " ");
nextNumber = next(nextNumber);
}
}
}
using System;
- ts.bharath March 05, 2015using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace series
{
class Program
{
static void Main(string[] args)
{
Int64 num = 12;
string strOut = num.ToString();
for(int i = 0; i < 10; i++)
{
Console.Write(strOut + " ");
strOut = PrintSeries(num);
Int64.TryParse(strOut,out num);
}
//PrintSeries(1);
Console.Read();
}
static string PrintSeries(Int64 num)
{
string temp, strOut = string.Empty;
int count = 1;
temp = num.ToString();
char prev = temp[0];
int length = temp.Length;
for (int i = 1; i < length; i++)
{
if (temp[i] == prev)
{
count++;
}
else if (temp[i] != prev)
{
strOut = strOut + count.ToString() + prev.ToString();
count = 1;
prev = temp[i];
}
if (i + 1 == length)
{
strOut = strOut + count.ToString() + prev.ToString();
count = 1;
prev = temp[i];
}
}
if (length == 1)
{
strOut = count.ToString() + temp;
}
return strOut;
}
}
}