fork download
  1. #include <iostream>
  2. using namespace std;
  3. struct field{
  4. string f;
  5. string s;
  6. int num;
  7. };
  8.  
  9. void removeNumbersAndCommas(string arr[], int n) {
  10. for (int i = 0; i < n; i++) {
  11. int j = 0; // Index for the current word
  12.  
  13. // Iterate over each character in the word
  14. while (arr[i][j] != '\0') {
  15. if (arr[i][j] >= '0' && arr[i][j] <= '9') {
  16. // If the character is a number, remove it by shifting the rest of the characters
  17. int k = j;
  18. while (arr[i][k] != '\0') {
  19. arr[i][k] = arr[i][k + 1];
  20. k++;
  21. }
  22. } else if (arr[i][j] == ',') {
  23. // If the character is a comma, remove it by shifting the rest of the characters
  24. int k = j;
  25. while (arr[i][k] != '\0') {
  26. arr[i][k] = arr[i][k + 1];
  27. k++;
  28. }
  29. } else {
  30. j++; // Move to the next character in the word
  31. }
  32. }
  33. }
  34. }
  35. void prints(field arr[], int n, string p[], string q[], string l[], string m[], string b[], int ind){
  36.  
  37. for(int i =0;i<n;i++){
  38. if(arr[i].num == 1){
  39. p[i] = arr[i%n].f;
  40. b[ind++] = p[i];
  41. q[i] = arr[i%n].s;
  42. b[ind++] = q[i];
  43.  
  44. }
  45. else if(arr[i].num ==0){
  46. l[i] = arr[i%n].f;
  47. b[ind++] = l[i];
  48. m[i] = arr[i%n].s;
  49. b[ind++] = m[i];
  50. }
  51. else{
  52. p[i] = arr[i%n].f;
  53. b[ind++] = p[i];
  54. q[i] = arr[i%n].f;
  55. b[ind++] = q[i];
  56. l[i] = arr[i%n].f;
  57. b[ind++] = l[i];
  58. m[i] = arr[i%n].f;
  59. b[ind++] = m[i];
  60. }
  61. }
  62. }
  63. void convert(string arr[], int n){
  64. for(int i=0; i<n; i++) {
  65. std::string word = arr[i];
  66. int len = word.length();
  67. std::string new_word = "";
  68. bool first_letter = true;
  69.  
  70. for(int j=0; j<len; j++) {
  71. if(isdigit(word[j])) {
  72. continue;
  73. }
  74. if(first_letter) {
  75. new_word += toupper(word[j]);
  76. first_letter = false;
  77. }
  78. else {
  79. new_word += tolower(word[j]);
  80. }
  81. }
  82. cout << new_word<<" ";
  83. }
  84. }
  85. void find(field arr[], int n, string b[]){
  86. string p[n], q[n], l[n], m[n];
  87. int ind = 0;
  88. prints(arr, n, p, q, l, m, b, ind);
  89. string r[4*n];
  90.  
  91. //removeNumbersAndCommas(b, n);
  92.  
  93. removeNumbersAndCommas(b, n);
  94.  
  95. for(int i = 0;i<4*n;i++){
  96. for(int j = i+1;j<4*n;j++){
  97. if(b[i]==b[j]){
  98. b[i] = "remove";
  99. }
  100. }
  101. }
  102. for(int i = 0;i<4*n;i++){
  103. if(b[i]!= "remove")
  104. r[i]= b[i];
  105. }
  106. convert(r, n);
  107. //for(int i =0;i<4*n;i++)
  108. //cout<<r[i]<<" ";
  109.  
  110. }
  111.  
  112. void f(field arr[], int n){
  113. string b[4*n];
  114. find(arr, n, b);
  115. }
  116. int main() {
  117. // your code goes here
  118. int n;
  119. cin>>n;
  120. field arr[n];
  121. for(int i =0;i<n;i++){
  122. cin>>arr[i].f>>arr[i].s>>arr[i].num;
  123. }
  124.  
  125. f(arr, n);
  126. return 0;
  127. }
Success #stdin #stdout 0.01s 5508KB
stdin
6
Jo4e Ma,Ry 1
ElizaB53et5h June 1
Joe John 0
Joe, JuNe 0
John JUne 1
Margaret
stdout
Joe Mary Elizabeth June Joe