fork 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] = "delete";
  110. }
  111. }
  112. }
  113. for(int i = 0;i<4*n;i++){
  114. if(b[i]!= "delete")
  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 sort(field arr[], int n) {
  132.  
  133. string p[n], q[n], l[n], m[n], b[4*n];
  134. prints(arr, n, p, q, l, m, b);
  135. int i = 0;
  136. bool swapped = true;
  137. while (i < n - 1 && swapped) {
  138. swapped = false;
  139. for (int j = 0; j < n - i - 1; j++) {
  140. int k = 0;
  141. while (b[j][k] == b[j + 1][k]) {
  142. k++;
  143. }
  144. if (b[j][k] > b[j + 1][k]) {
  145. string temp = b[j];
  146. b[j] = b[j + 1];
  147. b[j + 1] = temp;
  148. swapped = true;
  149. }
  150. }
  151. i++;
  152. }
  153. for(int i =0;i<4*n;i++){
  154. cout<<b[i]<<" ";
  155. }
  156. }
  157.  
  158.  
  159. void result(field arr[], int n){
  160.  
  161. removeDuplicates(arr, n);
  162. cout<<endl;
  163. removeNumbersAll(arr, n);
  164. cout<<endl;
  165. convertloweToUpp(arr, n);
  166. cout<<endl;
  167. sort(arr, n);
  168.  
  169. }
  170. int main() {
  171. // your code goes here
  172. int n;
  173. cin>>n;
  174. field arr[n];
  175. for(int i =0;i<n;i++){
  176. cin>>arr[i].f>>arr[i].s>>arr[i].num;
  177. }
  178. result(arr, n);
  179.  
  180. return 0;
  181. }
Success #stdin #stdout 0.01s 5504KB
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           
ElizaBet5h Jo4e Joe John June Ma,ry Joe, JuNe John JUne Margaret Margaret Margaret Margaret