Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Task1
- {
- public class Sentence
- {
- public Sentence(string sentence)
- {
- this.sentence = sentence;
- words = sentence.Split(new Char [] {' ', ',', '.', ':', '\t', '!', '?' });
- }
- public int calculateWordsCount()
- {
- return words.Length;
- }
- public string findLongestWord()
- {
- foreach(string word in words)
- {
- if(word.Length>longestword.Length)
- longestword = word;
- }
- return longestword;
- }
- public string[] words {get; set;}
- public string sentence {get; set;}
- public string longestword {get; set;} = "";
- public int wordsCount {get; set;}
- }
- class Program
- {
- static void Main(string[] args)
- {
- int n, indexMostWords=0, indexLongestWord=0;
- Console.Write("Enter n: ");
- n = Int32.Parse(Console.ReadLine());
- Sentence[] sentences = new Sentence[n];
- for(int i=0; i<n;i++)
- {
- sentences[i] = new Sentence(Console.ReadLine());
- }
- for(int i=0;i<n;i++)
- {
- if(sentences[i].findLongestWord().Length>sentences[indexLongestWord].findLongestWord().Length)
- {
- indexLongestWord = i;
- }
- if(sentences[i].calculateWordsCount()>sentences[indexMostWords].calculateWordsCount())
- {
- indexMostWords = i;
- }
- }
- Console.WriteLine("Sentence with most words is: \"{0}\"",sentences[indexMostWords].sentence);
- Console.WriteLine("Sentence with longest word is: \"{0}\"",sentences[indexLongestWord].sentence);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement