13 Replies - 464 Views - Last Post: 03 December 2012 - 01:44 AM Rate Topic: -----

#1 rockkrose  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 25-November 12

Letter list

Posted 02 December 2012 - 01:16 AM

Hello,

I'm trying to build a function that displays a list of letters in alphabetical order. It has an input parameter : int t. The output should be:

for t=1: --> output: "a b c d e f g h i j k l m n o p q r s t u v w x y z"
for t=2: --> output: "a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x z" -> for the second string letter y is substracted..
.
.
.


using System;

public class Program {

  public static string LetterList(int t) {
      string output = "";
      output = (char)('a')+" " + output;              
      for (int i = 1; i < 26-t; i++)
       {
        output = output + " " + (char)('a' + i);
       }  

      string output1 = output + " " +(char)('a' +25);
      string output2 = "";   
      for (int j = 0; j<t-0; j++) 
       {  
       output2 +=" "+output1 ;
       }   
     
     return output2;
  }
}




In my case:
for t=1: --> output: " a b c d e f g h i j k l m n o p q r s t u v w x y z"
for t=2: -->output: " a b c d e f g h i j k l m n o p q r s t u v w x z a b c d e f g h i j k l m n o p q r s t u v w x z" so for both strings letter y is substracted and it adds a space in front ....I would appreciate any suggestions. Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Letter list

#2 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Letter list

Posted 02 December 2012 - 01:29 AM

What do you want for t = 3?
Was This Post Helpful? 0
  • +
  • -

#3 rockkrose  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 25-November 12

Re: Letter list

Posted 02 December 2012 - 01:59 AM

View PostMomerath, on 02 December 2012 - 01:29 AM, said:

What do you want for t = 3?


hi,

I use an online program for learning c#, and it generates the output only for t=1 and t=2, In my opinion the output should be:


for t=3 -->"a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x z a b c d e f g h i j k l m n o p q r s t u v w z" ---> add string and substract 2 letters x and y ....
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3552
  • View blog
  • Posts: 11,013
  • Joined: 05-May 12

Re: Letter list

Posted 02 December 2012 - 09:14 AM

And happens when:
T = 26
T = 0
T = -1
Was This Post Helpful? 0
  • +
  • -

#5 rockkrose  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 25-November 12

Re: Letter list

Posted 02 December 2012 - 10:04 AM

View PostSkydiver, on 02 December 2012 - 09:14 AM, said:

And happens when:
T = 26
T = 0
T = -1


hi, you mean the second loop is wrong?
Was This Post Helpful? 0
  • +
  • -

#6 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3552
  • View blog
  • Posts: 11,013
  • Joined: 05-May 12

Re: Letter list

Posted 02 December 2012 - 10:10 AM

I'm not saying that the second loop is correct or incorrect. I'm just trying to understand the problem. What is supposed to be the output when t = 3, t = 26, t = 0, and t = -1?
Was This Post Helpful? 0
  • +
  • -

#7 rockkrose  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 25-November 12

Re: Letter list

Posted 02 December 2012 - 10:21 AM

View PostSkydiver, on 02 December 2012 - 10:10 AM, said:

I'm not saying that the second loop is correct or incorrect. I'm just trying to understand the problem. What is supposed to be the output when t = 3, t = 26, t = 0, and t = -1?

for t=3 -->"a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x z a b c d e f g h i j k l m n o p q r s t u v w z" ---> substract x and y from last sequence
fot t=4-->"a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x z a b c d e f g h i j k l m n o p q r s t u v w z a b c d e f g h i j k l m n o p q r s t u v z" substract w x y grom last sequence,

each time t increases string "a b c d e f g h i j k l m n o p q r s t u v w x y z" is added to the last sequence and a number of strings (t-1) before z are subtracted.
Was This Post Helpful? 0
  • +
  • -

#8 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3552
  • View blog
  • Posts: 11,013
  • Joined: 05-May 12

Re: Letter list

Posted 02 December 2012 - 10:54 AM

And what happens in the cases when t is 26, when t is 0, and when t is negative?

Sent from my T-Mobile G2 using Tapatalk 2
Was This Post Helpful? 0
  • +
  • -

#9 rockkrose  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 25-November 12

Re: Letter list

Posted 02 December 2012 - 11:00 AM

View PostSkydiver, on 02 December 2012 - 10:54 AM, said:

And what happens in the cases when t is 26, when t is 0, and when t is negative?

Sent from my T-Mobile G2 using Tapatalk 2


I'm not sure...I use an online tool(Pex for fun- is called) to solve c# problems and for this one it displays the output only for t=1 and t=2....:(

This post has been edited by rockkrose: 02 December 2012 - 11:03 AM

Was This Post Helpful? 0
  • +
  • -

#10 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3552
  • View blog
  • Posts: 11,013
  • Joined: 05-May 12

Re: Letter list

Posted 02 December 2012 - 01:22 PM

Can you post a link to the pex4fun.com problem?
Was This Post Helpful? 0
  • +
  • -

#11 rockkrose  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 25-November 12

Re: Letter list

Posted 02 December 2012 - 02:13 PM

View PostSkydiver, on 02 December 2012 - 01:22 PM, said:

Can you post a link to the pex4fun.com problem?

yes :)
http://www.pexforfun...62-c41e8dcbf277, on the left ->section :Duels -> LetterList
Was This Post Helpful? 0
  • +
  • -

#12 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3552
  • View blog
  • Posts: 11,013
  • Joined: 05-May 12

Re: Letter list

Posted 02 December 2012 - 03:03 PM

Playing with that challenge, apparently the only valid input values for t are 1, 2, 3, 4, and 5.
Was This Post Helpful? 1
  • +
  • -

#13 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Letter list

Posted 03 December 2012 - 01:10 AM

I found that challenge particularly dumb. Just hard code the strings with a switch statement. Some of the others ones are much better in that you actually have to figure out what is happening.
Was This Post Helpful? 1
  • +
  • -

#14 rockkrose  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 25-November 12

Re: Letter list

Posted 03 December 2012 - 01:44 AM

Thanks guys, I will follow your advices. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1