arrow_forward همه ارسال‌ها

جزئیات ارسال کد#550

code_blocks
مسئله مربوطه: سلام هاتکدز (#3) arrow_outward
verified
وضعیت داوری نهایی: پاسخ نادرست تست 1
terminal
زبان برنامه‌نویسی: C++
schedule
ارسال‌کننده و زمان:
shana (۲ سال پیش)
descriptionsolution.cpp ۱۰۱ خط • ۲٫۰ کیلوبایت
1#include <iostream>
2using namespace std;
3int main()
4{
5 int n , m , min;
6 cin >> n >> m;
7 int arr1[n] , arr2[m] , arr3[n + m];
8
9 for ( int i = 0 ; i < n ; i ++ )
10 {
11 cin >> arr1[i];
12 }
13
14 for ( int i = 0 ; i < m ; i ++ )
15 {
16 cin >> arr2[i];
17 }
18
19 for ( int i = 0 ; i < n ; i ++ )
20 {
21 for ( int j = 0 ; j < n ; j ++ )
22 {
23 if ( arr1[i] > arr1[j] && i < j )
24 {
25 swap ( arr1[i] , arr1[j] );
26 }
27 }
28 }
29
30 for ( int i = 0 ; i < m ; i ++ )
31 {
32 for ( int j = 0 ; j < m ; j ++ )
33 {
34 if ( arr2[i] > arr2[j] && i < j )
35 {
36 swap ( arr2[i] , arr2[j] );
37 }
38 }
39 }
40
41 min = arr1[0];
42 int i = 0;
43 int andx1 , andx2;
44 andx1 = 0;
45 andx2 = 0;
46 while ( i < (n + m) )
47 {
48 if ( min > arr2[andx2] )
49 {
50 arr3[i] = arr2[andx2];
51 andx2 ++;
52 min = arr2[andx2];
53
54 if ( andx2 > m - 1 && andx1 < n - 1 )
55 {
56 andx1 ++;
57 min = arr1[andx1];
58 }
59 }
60
61 else if ( min > arr1[andx1] )
62 {
63 arr3[i] = arr1[andx1];
64 andx1 ++;
65 min = arr1[andx1];
66
67 if ( andx1 > n - 1 && andx2 < m - 1 )
68 {
69 andx2 ++;
70 min = arr2[andx2];
71 }
72 }
73
74 else
75 {
76 arr3[i] = min;
77 if ( min == arr1[andx1] && andx1 < n - 1 )
78 {
79 andx1 ++;
80 min = arr1[andx1];
81 }
82
83 else if ( min == arr2[andx2] && andx2 < m - 1 )
84 {
85 andx2 ++;
86 min = arr2[andx2];
87 }
88 }
89
90 i ++;
91 }
92
93
94 for ( int i = 0 ; i < n + m ; i ++ )
95 {
96 cout << arr3[i] <<" ";
97 }
98
99
100 return 0;
101}
کد ارسال‌شده برای داوری خودکار هاتکدز UTF-8