Hello Everybody,
Could anybody do this program in C sharp?:
If the input is: AbcdeaDFGfAf
output should be:
AAa
Dd
Fff
Those
characters are occurring more than one time should display in order
from caps to small and those character occurring single time should not
display.
if somebody solve this i would be grateful to him.
Thanks&Regards,
Habib
Loading
Rajendra DeopuraPosted Jan 5, 2009, 9:26 AM
Try this code:
namespace problem
{
class Program
{
static void Main(string[] args)
{
string str = "AbcdeaDFGfAf";
char ch;
int k,j=0;
int count=0,count1=0;
Console.Clear();
for(ch='A';ch<='Z';ch++,j=0)
{
count=count1=0;
for(j=0;j
if(str[j]==ch)
count++;
if(str[j]==(ch+32))
count1++;
}
if(( count>=2|| count1>=2)|| (count+count1)>=2)
{
for(k=1;k<=count;k++)
Console.Write(ch);
for (k = 1; k <= count1; k++)
Console.Write(char.ToLower(ch));
Console.WriteLine();
}
}
}
}
}
Thanks
Happy Coding
Habibur RahamanPosted Jan 2, 2009, 12:38 AM
Thanks&Regards,
Habib
Jan MontanoPosted Jan 1, 2009, 9:33 PM
static
void Test1(){
// Ascii Code For 'A' = 65
// Ascii Code For 'B' = 66 // and so on... // Ascii Code For 'Z' = 90 // Ascii Code For 'a' = 97 // Ascii Code For 'b' = 98 // and so on... // Ascii Code For 'z' = 122 Hashtable characterTable = new Hashtable(); // initialize characterTable with keys 'A' to 'Z' having empty values. for (int index=65; index<=90; index++){
characterTable.Add(index,
"");}
//string input = "AbcdeaDFGfAf"; Console.WriteLine("Input:\n"); string input = Console.ReadLine(); int asciiCode = 0; int lowerCaseAsciiCode = 0; for (int i = 0; i < input.Length; i++ ){
// check if it's a character because we're only interested in characters. A-Z,a-z. if (char.IsLetter(input[i])){
// ascii codes for characters are either 65-90 (A-Z), or 97-122 (a-z)asciiCode = input[i];
// check if it's uppercase if (asciiCode <= 90){
characterTable[asciiCode] = input[i] + characterTable[asciiCode].ToString();
}
else{
// it's lower caselowerCaseAsciiCode = asciiCode - 32;
characterTable[lowerCaseAsciiCode] = characterTable[lowerCaseAsciiCode].ToString() + input[i];
}
}
}
Console.WriteLine(); // display output for (int j = 65; j <= 90; j++){
string letters = characterTable[j] as string; if (letters.Length > 1){
Console.WriteLine(letters);}
}
Console.Read();}