fork(1) download
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. const int MAX_SIZE = 1000;
  6.  
  7. bool isLetter(char c) {
  8. return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
  9. }
  10.  
  11. bool isBigLetter(char c) {
  12. return c >= 'A' && c <= 'Z';
  13. }
  14.  
  15. bool isSmallLetter(char c) {
  16. return c >= 'a' && c <= 'a';
  17. }
  18.  
  19. bool checkCaps(char text[]) {
  20. int n = strlen(text);
  21. for (int i = 0; i < n; ++i) {
  22. if (isBigLetter(text[i])) {
  23. text[i] -= ('a' - 'A');
  24. }
  25. }
  26. return strstr(text, "caps") == 0;
  27. }
  28.  
  29. void processWords(char text[], bool &capsLock) {
  30. int n = strlen(text), lettersCount = 0;
  31. bool isWord = false;
  32. for (int i = 0; i <= n; ++i) {
  33. if (isLetter(text[i])) {
  34. if (isBigLetter(text[i]) && capsLock) {
  35. text[i] += ('a' - 'A');
  36. }
  37. if (isSmallLetter(text[i]) && !capsLock) {
  38. text[i] -= ('a' - 'A');
  39. }
  40. isWord = true;
  41. ++lettersCount;
  42. } else if (isWord) {
  43. char temp = text[i];
  44. text[i] = 0;
  45. cout << text + i - lettersCount << ", ";
  46. if (checkCaps(text + i - lettersCount)) {
  47. if (!capsLock) {
  48. capsLock = true;
  49. } else {
  50. capsLock = false;
  51. }
  52. }
  53. text[i] = temp;
  54. isWord = false;
  55. lettersCount = 0;
  56. }
  57. }
  58. }
  59.  
  60. int main() {
  61. char text[MAX_SIZE + 1] = {0};
  62. bool capsLock = false;
  63. while (cin.getline(text, MAX_SIZE + 1)) {
  64. processWords(text, capsLock);
  65. }
  66. return 0;
  67. }
Success #stdin #stdout 0.01s 5280KB
stdin
Textul MIC caps acum este
mareEE Caps, nu-I asa?
stdout
Textul, mic, cAps, acum, este, mareee, CAps, nu, I, asa,