fork(5) download
  1. using static System.Console;
  2. using System;
  3.  
  4. public class Program {
  5. public static void Main() {
  6. WriteLine(Abreviatte("Rafael Rodrigues Arruda de Oliveira"));
  7. WriteLine(Abreviatte("Rafael Rodrigues Arruda De Oliveira"));
  8. }
  9. public static string Abreviatte(string nome) {
  10. var meio = " ";
  11. var nomes = nome.Split(' ');
  12. for (var i = 1; i < nomes.Length - 1; i++) {
  13. if (!nomes[i].Equals("de", StringComparison.OrdinalIgnoreCase) &&
  14. !nomes[i].Equals("da", StringComparison.OrdinalIgnoreCase) &&
  15. !nomes[i].Equals("do", StringComparison.OrdinalIgnoreCase) &&
  16. !nomes[i].Equals("das", StringComparison.OrdinalIgnoreCase) &&
  17. !nomes[i].Equals("dos", StringComparison.OrdinalIgnoreCase))
  18. meio += nomes[i][0] + ". ";
  19. }
  20. return nomes[0] + meio + nomes[nomes.Length - 1];
  21. }
  22. }
  23.  
  24. //https://pt.stackoverflow.com/q/366582/101
Success #stdin #stdout 0.02s 15848KB
stdin
Standard input is empty
stdout
Rafael R. A. Oliveira
Rafael R. A. Oliveira