Wipro Technologies Interview Question for Software Engineer / Developers


Team: Rainbow
Country: India
Interview Type: Written Test




Comment hidden because of low score. Click to expand.
0
of 0 vote

Is it as simple as the following code?

#include <stdio.h>

void parse(const char* src)
{
    int times;
    char c;
    for(; c = *src; src += 2){
        sscanf(src+1, "%d", &times);
        for(; times > 0; --times) putchar(c);
    }
}

int main()
{
    parse("a3b2c4");
    
    getchar();
    return 0;
}

- uuuouou December 02, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Sorry for the misleading code above. I was being stupid again.

#include <stdio.h>
#include <ctype.h>
void parse(const char* src)
{
    int times;
    char c, *p;
    for(; c = *src; src = p){
        sscanf(src+1, "%d", &times);
        for(; times > 0; --times) putchar(c);
        for(p = src+2; isdigit(*p); ++p) ; 
    }
}

int main()
{
    parse("a3b2c4");
    
    getchar();
    return 0;
}

- uuuouou December 02, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I definitely can not get the job! There's a bug in the code above again.

#include <stdio.h>
#include <ctype.h>
void parse(const char* src)
{
    int times;
    char c;
    for(; c = *src; ){
        sscanf(src+1, "%d", &times);
        for(; times > 0; --times) putchar(c);
        for(src += 2; isdigit(*src); ++src) ; 
    }
}

int main()
{
    parse("a3b2c4");
    
    getchar();
    return 0;
}

- uuuouou December 02, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

did you test if it works?

- confused_banda December 02, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

C++ version.

#include <iostream>
#include <sstream>
#include <stdexcept>

std::string decode(const std::string& str) {
	std::stringstream ss(str);
	std::string out;
	out.reserve(str.size() * 3); // estimated size to avoid reallocation

	while (!ss.eof()) {
		char c; int n;
		ss >> c >> n;
		if (ss.fail())
			throw std::invalid_argument("can't decode");
		out.append(n, c);
	
	}
	return out;
}

int main() {
	std::cout << decode("a3b2c4") << std::endl;
	return 0;
}

- Diego Giagio December 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Here is the code....
#include <stdio.h>
#include <string.h>
int main()
{
char a[8]="a3b4c2";
int i,j,p;
double q;
gets(a);

for(i=0;i<strlen(a);i=i+2)
{
p=a[i+1] - '0';
for(j=p;j>0;j--)
{
printf("%c",a[i]);
}
}
return 0;
}

- Asis Dey December 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String[] args) {
		
		String str= "a13b2c14d15";		
		Map<Character, Integer> alphaMap= new LinkedHashMap<>();		
		
		int count=0;
		char hold='\0';
		boolean flag=false;
		for(int i=0;i<str.length();i++)
		{
			if(str.charAt(i)<'0'||str.charAt(i)>'9')
				{

				flag=true;
				count=0;
				hold=str.charAt(i);				
				}
			else
			{			  	
			  count=count*10+(str.charAt(i)-48);
			  
			}
			if(flag)
			{
				alphaMap.put(hold, count);
			}
		}
		
		System.out.println(alphaMap);
		
		Set<Character> charSet= alphaMap.keySet();
		
		for(char c:charSet)
		{
			for(int i=0;i<alphaMap.get(c);i++)
			{
				System.out.print(c);
			}
		}
	}

- Ghosh January 10, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int main()
{
	char *str = "a1b10c4";
	char ch;
	long count=0;
	int m;
	while(*str != '\0')
	{
		ch = *str;
		sscanf(str + 1, "%ld", &count);
		for(m=0; m<count; m++)
			printf("%c", ch);
		str++;
		while(*str >= '0' && *str <= '9')
			str++;
	}
	return 0;
}

- sagar019 January 25, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Writing Code? Surround your code with

and

to preserve whitespace.

- Anonymous August 31, 2015 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More