ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1601. AntiCAPS

C#
Posted by Maxim Afripov 2 Nov 2021 00:08
1) Input text
2) Compare each character with:
    letter
    punctuation
3) Output with changes

using System;
using System.Collections.Generic;
namespace AntiCAPS {
    public class Program {
        public static void Main(string[] args) {
            bool _newSentence = true;
            string message = Console.In.ReadToEnd().ToLower();
            List<char> punctuation = new List<char>(new char[] { '!', '.', '?' });
            for (int iterable = 0; iterable < message.Length; iterable++) {
                if ((int)message[iterable] >= 97 && (int)message[iterable] <= 122) {
                    if (_newSentence) {
                        Console.Write(Char.ToUpper(message[iterable]));
                        _newSentence = false;
                    } else Console.Write(message[iterable]);
                } else if (punctuation.Contains(message[iterable])) {
                    _newSentence = true;
                    Console.Write(message[iterable]);
                } else Console.Write(message[iterable]);
            }
        }
    }
}

Edited by author 02.11.2021 00:10