Skip to content

Commit 718d570

Browse files
committed
a2oj added
1 parent 4dba22b commit 718d570

5 files changed

+167
-0
lines changed

A2OJ/A/071. Eugeny and Array.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
int main()
5+
{
6+
int n, m, a, l, r, c(0), d(0);
7+
scanf("%d%d", &n, &m);
8+
while (n--)
9+
{
10+
scanf("%d", &a);
11+
if (a == 1)
12+
{
13+
c += 1;
14+
}
15+
else
16+
{
17+
d += 1;
18+
}
19+
}
20+
int up = min(c, d) * 2;
21+
while (m--)
22+
{
23+
scanf("%d%d", &l, &r);
24+
printf((r - l) % 2 == 1 && r - l < up ? "1\n" : "0\n");
25+
}
26+
return 0;
27+
}
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
int main ()
5+
{
6+
int n,x,y;
7+
int i,j;
8+
cin>>n;
9+
int a[n];
10+
for(i=0;i<n;i++)
11+
cin>>a[i];
12+
for(i=0;i<n-2;i++)
13+
{
14+
x=y=0;
15+
for(j=i+2;j<n;j++)
16+
{
17+
if((a[j]>a[i]&&a[j]>a[i+1])||(a[j]<a[i]&&a[j]<a[i+1]))
18+
x++;
19+
else
20+
y++;
21+
}
22+
if(x&&y)
23+
{
24+
cout<<"yes";
25+
return 0;
26+
}
27+
}
28+
cout<<"no";
29+
return 0;
30+
}

A2OJ/A/073. Reconnaissance 2.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <bits/stdc++.h>
2+
#define lli long long int
3+
#define endl "\n"
4+
using namespace std;
5+
6+
int main()
7+
{
8+
int n;
9+
cin>>n;
10+
int a[n];
11+
for(int i=0; i<n;i++)
12+
cin>>a[i];
13+
int mindiff = INT_MAX;
14+
int x,y;
15+
for(int i=0; i<n-1;i++)
16+
{
17+
if(abs(a[i] - a[i+1]) < mindiff)
18+
{
19+
mindiff = abs(a[i] - a[i+1]);
20+
x = i+1;
21+
y = i+1+1;
22+
}
23+
}
24+
if(abs(a[0] - a[n-1]) < mindiff)
25+
{
26+
mindiff = abs(a[0] - a[n-1]);
27+
x = 1;
28+
y = n;
29+
}
30+
cout<<x<<" "<<y;
31+
32+
return 0;
33+
}
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <bits/stdc++.h>
2+
#define lli long long int
3+
#define endl "\n"
4+
using namespace std;
5+
6+
int main()
7+
{
8+
int a , b, c,d;
9+
int c1,c2,r1,r2,d1,d2;
10+
cin>>r1>>r2>>c1>>c2>>d1>>d2;
11+
for(a = 1 ; a<=9 ; a++)
12+
{
13+
for(b = 1; b<=9; b++)
14+
{
15+
for(c= 1; c<=9; c++)
16+
{
17+
for(d = 1; d<=9; d++)
18+
{
19+
if((r1 == (a+b)) and (r2 == (c+d)) and (c1 == (a+c)) and (c2 == (b+d)) and (d1 == (a+d)) and (d2 == (b+c)))
20+
{
21+
cout<<a<<" "<<b<<endl;
22+
cout<<c<<" "<<d<<endl;
23+
return 0;
24+
}
25+
}
26+
}
27+
}
28+
}
29+
30+
return 0;
31+
}

A2OJ/A/075. Comparing Strings.cpp

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
string s1,s2;
7+
cin>>s1>>s2;
8+
int i=0;
9+
if(s1.length() != s2.length())
10+
{
11+
cout<<"NO";
12+
return 0;
13+
}
14+
int err = 0,er1 = -1,er2;
15+
while(i < (s1.length()))
16+
{
17+
if(s1[i] != s2[i])
18+
{
19+
err++;
20+
if(er1 != -1)
21+
er2 = i;
22+
else
23+
er1 = i;
24+
}
25+
if(err > 2)
26+
{
27+
cout<<"NO";
28+
return 0;
29+
}
30+
i++;
31+
}
32+
if(err == 0)
33+
cout<<"YES";
34+
else if (err == 1)
35+
cout<<"NO";
36+
else
37+
{
38+
if((s1[er1] == s2[er2]) and (s1[er2] == s2[er1]))
39+
cout<<"YES";
40+
else
41+
cout<<"NO";
42+
}
43+
44+
return 0;
45+
46+
}

0 commit comments

Comments
 (0)