Programming Taskbook


E-mail:

Password:

User registration   Restore password

Russian

SFedU

1100 training tasks on programming

©  M. E. Abramyan (Southern Federal University), 1998–2018

 

Tasks | Task groups | String

PrevNext


Characters and strings

Characters and strings: basic operations

All input strings are assumed to contain no overlapping occurrences of a required substring in the tasks connected with search and replacement. Furthermore, substring removing (in String32 and String35) or substring replacement (in String38) do not lead to new occurrences of this substring in the given string.

String1. Given a character C, output its numeric value in the character set.

String2. Given an integer N (32 ≤ N ≤ 126), output a character with the numeric value N in the character set.

String3. Given a character C, output two characters: the first character precedes C in the character set, the second one follows C in the character set.

String4. Given an integer N (1 ≤ N ≤ 26), output N first capital (that is, uppercase) letters of the English alphabet ("A", "B", "C", and so on).

String5. Given an integer N (1 ≤ N ≤ 26), output N last small (that is, lowercase) letters of the English alphabet in inverse order ("z", "y", "x", and so on).

String6. A character C representing a digit or a letter of the Latin alphabet is given. If C is a digit then output the string "digit", if C is a capital letter then output the string "capital", otherwise output the string "small".

String7. Given a nonempty string, output numeric values of its first and last character in the character set.

String8. Given an integer N (> 0) and a character C, output a string that is of length N and contains characters C.

String9. Given an even integer N (> 0) and two characters C1, C2, output a string that is of length N, begins with C1, and contains alternating characters C1 and C2.

String10. Given a string, output a new string that contains the given string characters in inverse order.

String11. Given a nonempty string, output a new string that contains the given string characters separated by a blank character.

String12. Given a nonempty string and an integer N (> 0), output a new string that contains the given string characters separated by N characters "*".

String13. Given a string, find the amount of digits in the string.

String14. Given a string, find the amount of Latin capital letters in the string.

String15. Given a string, find the amount of Latin letters in the string.

String16. Given a string, convert all Latin capital letters of the string to lowercase.

String17. Given a string, convert all Latin small letters of the string to uppercase.

String18. Given a string, convert all Latin capital letters of the string to lowercase and all Latin small letters of the string to uppercase.

String19. A string is given. If the string represents an integer then output 1, if the string represents a real number (with nonzero fractional part) then output 2, otherwise output 0. A fractional part of a real number is preceded by the decimal point ".".

String20. Given a positive integer, output all digit characters in the decimal representation of the integer (from left to right).

String21. Given a positive integer, output all digit characters in the decimal representation of the integer (from right to left).

String22. Given a string that represents a positive integer, output the sum of digits of this integer.

String23. Given a string that represents an arithmetic expression of the form "<digit>±< digit>±…±<digit>" with operators "+" and "−" only (for example, "4+7−2−8"), output the value of given expression as an integer.

String24. Given a string with the binary representation of a positive integer, output a new string with the decimal representation of this integer.

String25. Given a string with the decimal representation of a positive integer, output a new string with the binary representation of this integer.

String26. An integer N (> 0) and a string S are given. Transform the string S to a new string of length N as follows: if the length of S is greater than N then remove its first characters, if the length of S is less than N then add characters "." to the beginning of S.

String27. Two positive integers N1, N2 and two strings S1, S2 are given. Output new string that contains N1 first characters of the string S1 and N2 last characters of the string S2 (in that order).

String28. Given a character C and a string S, double each occurrence of the character C in the string S.

String29. Given a character C and two strings S, S0, insert the string S0 into the string S before each occurrence of the character C.

String30. Given a character C and two strings S, S0, insert the string S0 into the string S after each occurrence of the character C.

String31. Two strings S, S0 are given. If the string S0 is a substring of S then output True, otherwise output False.

String32. Two strings S, S0 are given. Find the amount of occurrences of S0 in the string S.

String33. Two strings S, S0 are given. Remove the first occurrence of S0 from the string S. If the string S does not contain required substrings then do not change it.

String34. Two strings S, S0 are given. Remove the last occurrence of S0 from the string S. If the string S does not contain required substrings then do not change it.

String35. Two strings S, S0 are given. Remove all occurrences of S0 from the string S. If the string S does not contain required substrings then do not change it.

String36. Three strings S, S1, S2 are given. Replace the first occurrence of S1 in the string S by the string S2.

String37. Three strings S, S1, S2 are given. Replace the last occurrence of S1 in the string S by the string S2.

String38. Three strings S, S1, S2 are given. Replace all occurrences of S1 in the string S by the string S2.

String39. A string with at least one blank character is given. Output the substring of S that contains all characters between the first and the second blank character. If the string S contains only one blank character then output an empty string.

String40. A string with at least one blank character is given. Output the substring of S that contains all characters between the first and the last blank character. If the string S contains only one blank character then output an empty string.

Characters and strings: word processing

In this subgroup of tasks all input strings are assumed to be nonempty and without leading and trailing blank characters.

String41. A string that contains English words separated by one or more blank characters is given. Find the amount of words in the string.

String42. A string that contains English words separated by one or more blank characters is given. All string letters are in uppercase. Find the amount of words whose first letter is coincides with the last one.

String43. A string that contains English words separated by one or more blank characters is given. All string letters are in uppercase. Find the amount of words containing at least one letter "E".

String44. A string that contains English words separated by one or more blank characters is given. All string letters are in uppercase. Find the amount of words containing exactly three letters "E".

String45. A string that contains English words separated by one or more blank characters is given. Find the length of the shortest word.

String46. A string that contains English words separated by one or more blank characters is given. Find the length of the longest word.

String47. A string that contains English words separated by one or more blank characters is given. Output a new string that contains the given words (in the same order) separated by one character ".".

String48. A string that contains English words separated by one or more blank characters is given. All string letters are in uppercase. Process each word as follows: replace all next occurrences of its first letter by the character "." (for example, the word "MINIMUM" must be transformed into "MINI.U."). Do not change blank characters in the string.

String49. A string that contains English words separated by one or more blank characters is given. All string letters are in uppercase. Process each word as follows: replace all previous occurrences of its last letter by the character "." (for example, the word "MINIMUM" must be transformed into ".INI.UM"). Do not change blank characters in the string.

String50. A string that contains English words separated by one or more blank characters is given. Output a new string that contains the given words in inverse order. The words must be separated by one blank character.

String51. A string that contains English words separated by one or more blank characters is given. All string letters are in uppercase. Output a new string that contains the given words in alphabetic order. The words must be separated by one blank character.

String52. A string with an English sentence is given. Convert the first letter of each word to uppercase. A word is defined as a character sequence that does not contain blank characters and is bounded by blank characters or the string beginning/end. If the first word character is not a letter then do not change this word.

String53. A string with an English sentence is given. Find the amount of punctuation marks in the string.

String54. A string with an English sentence is given. Find the amount of vowels ("a", "i", "e", "o", "u") in the string.

String55. A string with an English sentence is given. Output the longest word in the string. If there are several words of the maximal length then output the first one. A word is defined as a character sequence that does not contain blank characters, punctuation marks and is bounded by blank characters, punctuation marks or the string beginning/end.

String56. A string with an English sentence is given. Output the shortest word in the string. If there are several words of the maximal length then output the last one. A word is defined as a character sequence that does not contain blank characters, punctuation marks and is bounded by blank characters, punctuation marks or the string beginning/end.

String57. A string with an English sentence is given. Remove all superfluous blank characters in the string, so that its words were separated by exactly one blank character.

Characters and strings: additional tasks

String58. A string that contains a fully qualified path name (that is, the drive and directory parts, the file name and extension) is given. Extract the file name (without the path and extension) from the string.

String59. A string that contains a fully qualified path name (that is, the drive and directory parts, the file name and extension) is given. Extract the extension (without the preceding dot character) from the string.

String60. A string that contains a fully qualified path name (that is, the drive and directory parts, the file name and extension) is given. Extract the first directory name (without backslashes "\") from the string. If the file with the given name is located in the root directory then output a backslash.

String61. A string that contains a fully qualified path name (that is, the drive and directory parts, the file name and extension) is given. Extract the last directory name (without backslashes "\") from the string. If the file with the given name is located in the root directory then output a backslash.

String62. A string with an English sentence is given. Encrypt the string using the right cyclic shift of any letter by one position of the English alphabet (for instance, the letter "A" is encoded by the letter "B", "a" is encoded by "b", "B" is encoded by "C", "z" is encoded by "a", and so on). Do not change blank characters and punctuation marks.

String63. A string with an English sentence and an integer K (0 < K < 10) are given. Encrypt the string using the right cyclic shift of any letter by K positions of the English alphabet (for instance, if K = 2 then the letter "A" is encoded by the letter "C", "a" is encoded by "c", "B" is encoded by "D", "z" is encoded by "b", and so on). Do not change blank characters and punctuation marks.

String64. A string with an encrypted English sentence and an integer K (0 < K < 10) are given. The string is encrypted by means of the right cyclic shift of any letter by K positions of the English alphabet (see String63). Decrypt the given string.

String65. A string with an encrypted English sentence and its decrypted first character C are given (the character C is always an English letter). The string is encrypted by means of the right cyclic shift of any letter by K positions of the English alphabet (see String63). Find the number K and decrypt the given string.

String66. A string with an English sentence is given. Encrypt the string by moving all characters that are at the string positions with even numbers (2, 4, …) to the beginning of the string (in the same order) and moving all characters that are at the string positions with odd numbers (1, 3, …) to the end of the string (in inverse order). For instance, the string "Program" must be encrypted to "rgamroP".

String67. A string with an encrypted English sentence is given (the method of encryption is described in String66). Decrypt the string.

String68. A string that contains digits and Latin small letters is given. If letters of the string are in alphabetic order then output 0, otherwise output the order number of the first string character that is a letter and breaks the required order.

String69. A string that contains Latin letters and parentheses "(", ")" is given. If parentheses are in correct order (that is, each closing parenthesis ")" corresponds to an opening one "(") then output 0. If the string contains illegal parentheses ")" then output the order number of the first string character that is an illegal ")". If the amount of closing parentheses is less than the amount of opening ones then output −1.

String70. A string that contains Latin letters and brackets of three types (parentheses "()", square brackets "[]", braces "{}") is given. If brackets are in correct order (that is, each closing bracket corresponds to an opening one of the same type) then output 0. If the string contains illegal closing brackets then output the order number of the first string character that is an illegal closing bracket. If the amount of closing brackets is less than the amount of opening ones then output −1.


PrevNext

 

  @Mail.ru

Designed by
M. E. Abramyan and V. N. Braguilevsky

Last revised:
06.05.2018