fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3. struct field{
  4. string f;
  5. string s;
  6. int num;
  7. };
  8. void prints(field arr[], int n, string p[], string q[], string l[], string m[], string b[]){
  9. int ind =0;
  10. for(int i =0;i<n;i++){
  11. if(arr[i].num == 1){
  12. p[i] = arr[i%n].f;
  13. b[ind++] = p[i];
  14. q[i] = arr[i%n].s;
  15. b[ind++] = q[i];
  16.  
  17. }
  18. else if(arr[i].num ==0){
  19. l[i] = arr[i%n].f;
  20. b[ind++] = l[i];
  21. m[i] = arr[i%n].s;
  22. b[ind++] = m[i];
  23. }
  24. else{
  25. p[i] = arr[i%n].f;
  26. b[ind++] = p[i];
  27. q[i] = arr[i%n].f;
  28. b[ind++] = q[i];
  29. l[i] = arr[i%n].f;
  30. b[ind++] = l[i];
  31. m[i] = arr[i%n].f;
  32. b[ind++] = m[i];
  33. }
  34. }
  35. }
  36. bool isDigi(char c){
  37. if(c=='0'||c=='1'||c=='2'||c=='3'||c=='4'||c=='5'||c=='6'||c=='7'||c=='8'||c=='9'){
  38. return true;
  39.  
  40. }
  41. return false;
  42. }
  43.  
  44. void removeNumbers(string str)
  45. {
  46. int current = 0;
  47. for(int i = 0; i< str.length(); i++){
  48. if(!isDigi(str[i])&&(str[i]!= ',')){
  49. str[current] = str[i];
  50. current++;
  51. }
  52. }
  53.  
  54. for(int i =0;i<current;i++){
  55. cout<<str[i];
  56. }
  57. }
  58. void lower(char C){
  59. int asc = C;
  60. if(C>='A' && C<='Z'){
  61.  
  62. asc = asc+32;
  63. char clower;
  64. clower = asc;
  65. cout<<clower;
  66. }
  67. else if(C>='a' && C<='z')
  68. cout<<C;
  69.  
  70.  
  71. }
  72.  
  73. void lowerIntoUpp(char c){
  74. if(c>='a'&&c<='z'){
  75. c = c-32;
  76. cout<<c;
  77. }
  78. else if(c>='A'&&c<='Z'){
  79. cout<<c;
  80. }
  81. }
  82. void convert(string str){
  83. lowerIntoUpp(str[0]);
  84. for(int i = 1;i<str.length();i++){
  85. lower((str[i]));
  86. }
  87. }
  88.  
  89. void removeNumbersAll(field arr[], int n){
  90. string p[n], q[n], l[n], m[n], b[4*n];
  91. prints(arr, n, p, q, l, m, b);
  92.  
  93. for(int i =0;i<4*n;i++){
  94. removeNumbers(b[i]);
  95. cout<<" ";
  96.  
  97. }
  98.  
  99. }
  100. void removeDuplicates(field arr[], int n){
  101. string p[n], q[n], l[n], m[n], b[4*n];
  102. prints(arr, n, p, q, l, m, b);
  103.  
  104. string r[4*n];
  105.  
  106. for(int i = 0;i<4*n;i++){
  107. for(int j = i+1;j<4*n;j++){
  108. if(b[i]==b[j]){
  109. b[i] = "remove";
  110. }
  111. }
  112. }
  113. for(int i = 0;i<4*n;i++){
  114. if(b[i]!= "remove")
  115. r[i]= b[i];
  116. }
  117. for(int i =0;i<4*n;i++)
  118. cout<<r[i]<<" ";
  119.  
  120. }
  121. void convertloweToUpp(field arr[], int n){
  122. string p[n], q[n], l[n], m[n], b[4*n];
  123. prints(arr, n, p, q, l, m, b);
  124. for(int i =0;i<4*n;i++){
  125. convert(b[i]);
  126. cout<<" ";
  127.  
  128. }
  129.  
  130. }
  131. void sorted(field arr[], int n){
  132. string p[n], q[n], l[n], m[n], b[4*n];
  133. prints(arr, n, p, q, l, m, b);
  134. //sort(b, n);
  135.  
  136. }
  137. void sort(string arr[], int n) {
  138. int i = 0;
  139. bool swapped = true;
  140. while (i < n - 1 && swapped) {
  141. swapped = false;
  142. for (int j = 0; j < n - i - 1; j++) {
  143. int k = 0;
  144. while (arr[j][k] == arr[j + 1][k]) {
  145. k++;
  146. }
  147. if (arr[j][k] > arr[j + 1][k]) {
  148. string temp = arr[j];
  149. arr[j] = arr[j + 1];
  150. arr[j + 1] = temp;
  151. swapped = true;
  152. }
  153. }
  154. i++;
  155. }
  156. for(int i =0;i<n;i++){
  157. cout<<arr[i]<<" ";
  158. }
  159. }
  160.  
  161. void result(field arr[], int n){
  162.  
  163. removeDuplicates(arr, n);
  164. removeNumbersAll(arr, n);
  165. convertloweToUpp(arr, n);
  166. // sorted(arr, n);
  167.  
  168. }
  169. int main() {
  170. // your code goes here
  171. int n;
  172. cin>>n;
  173. field arr[n];
  174. for(int i =0;i<n;i++){
  175. cin>>arr[i].f>>arr[i].s>>arr[i].num;
  176. }
  177. result(arr, n);
  178.  
  179. return 0;
  180. }
Success #stdin #stdout 0.01s 5516KB
stdin
6
Jo4e Ma,ry 1
ElizaBet5h June 1
Joe John 0
Joe, JuNe 0
John JUne 1
Margaret
stdout
Jo4e Ma,ry ElizaBet5h June Joe  Joe, JuNe John JUne    Margaret           Joe Mary ElizaBeth June Joe John Joe JuNe John JUne Margaret Margaret Margaret Margaret           Joe Mary Elizabeth June Joe John Joe June John June Margaret Margaret Margaret Margaret