Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding some codeforces problems with solutions #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions codeforce/Anton and Danik.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
n = int(input())
s = input()
if s.count('A')>s.count('D'):
print("Anton")
if s.count('A')<s.count('D'):
print('Danik')
if s.count('A') == s.count('D'):
print('Friendship')
7 changes: 7 additions & 0 deletions codeforce/Anton and Letters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def get_dis(s):
return len(set(s))-4
s = input()
if len(s) == 2:
print(0)
else:
print(abs(get_dis(s)))
15 changes: 15 additions & 0 deletions codeforce/Anton and Polyhedrons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
n = int(input())
t = 0
for i in range(n):
s = input()
if s == "Tetrahedron":
t = t+4
if s == "Cube":
t = t+6
if s == "Octahedron":
t = t+8
if s == "Dodecahedron" :
t = t+12
if s == "Icosahedron" :
t = t+20
print(t)
9 changes: 9 additions & 0 deletions codeforce/Bear and Big Brother.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
a,b = map(int,input().split())
x = 1
while True :
a = a*3
b = b*2
if a>b :
break
x =x+1
print(x)
26 changes: 26 additions & 0 deletions codeforce/Beautiful Matrix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include<iostream>
#include <cstdlib>
using namespace std;
int main()
{
int arr[5][5];
int b=0,r=0,c=0;
for (int i=0;i<5;i++)
{
for (int j =0;j<5;j++ )
{
cin>>arr[i][j];
}
}
for(int i=0;i<5;i++)
{
for(int j=0;j<5;j++)
{
if (arr[i][j] == 1)
{
cout<<abs(3-(i+1))+abs(3-(j+1));
break;
}
}
}
}
9 changes: 9 additions & 0 deletions codeforce/Bit++.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
n = int(input())
x=0
for i in range(n):
s = input()
if '+' in s:
x+=1
else:
x-=1
print(x)
33 changes: 33 additions & 0 deletions codeforce/Black square.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include<iostream>
using namespace std;
int main()
{
int sum=0,a=0,b=0,c=0,d=0;
int arr[4];
for (int i=0;i<4;i++)
{
cin>>arr[i];
}
string s;
cin>>s;
for(int i=0;i<s.length();i++)
{
if (s[i] == '1')
{
a++;
}
else if ( s[i] == '2')
{
b++;
}
else if ( s[i] == '3')
{
c++;
}
else {
d++;
}
}
sum = (a*arr[0])+(b*arr[1])+(c*arr[2])+(d*arr[3]);
cout<<sum;
}
5 changes: 5 additions & 0 deletions codeforce/Boy or Girl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
word = input()
if len(set(word))%2 == 0:
print("CHAT WITH HER!")
else:
print("IGNORE HIM!")
5 changes: 5 additions & 0 deletions codeforce/Calculating Function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
n = int(input())
if n%2 == 0:
print(n//2)
else:
print((-n-1)//2)
17 changes: 17 additions & 0 deletions codeforce/Free ice cream.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a,b;
int m;
int c;
cin>>a>>b;
m=max(a,b);
c=(6-(a-1))/6;
cout<<c;




}
23 changes: 23 additions & 0 deletions codeforce/Games.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include<iostream>
using namespace std;
int main()
{
int ans=0;
int n;cin>>n;
int h[n],a[n];
for(int k=0;k<n;k++)
{
cin>>h[k]>>a[k];
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if (i!=j && h[i] == a[j] )
{
++ans;
}
}
}
cout<<ans;
}
30 changes: 30 additions & 0 deletions codeforce/Gravity Flip.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include<iostream>
using namespace std;
int main()
{
int n;cin>>n;
int arr[n];
int temp;
for (int k=0;k<n;k++)
{
cin>>arr[k];
}
for(int i = 0;i<n;i++)
{
for (int j = i+1;j<n;j++)
{
if(arr[j] <arr[i] )
{
temp=arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
for ( int k=0;k<n;k++)
{
cout<<arr[k]<<" ";
}


}
16 changes: 16 additions & 0 deletions codeforce/Helpful Maths.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
word = input()
l = []
if len(word) <= 1:
print(word)
else:
for i in word:
if i.isdigit():
l.append(int(i))

N_word = ""
l.sort()
for k in l :
N_word = N_word + '+' + str(k)

print(N_word[1:])

21 changes: 21 additions & 0 deletions codeforce/Hulk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
n = int(input())
s = ""
for i in range(1,n+1):
s = s+" "+ "I"
if i != n:
if i%2 != 0:
s = s+" "+ "hate that"
#print("hate that")
else:
s = s+" "+ "love that"
#print("love that")
else:
if n%2 != 0:
s = s+" "+ "hate"
#print("hate")
else:
s = s+" "+ "love"
#print("love")
s = s+" "+ "it"
print(s)

10 changes: 10 additions & 0 deletions codeforce/Insomnia cure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
k = int(input())
l = int(input())
m = int(input())
n = int(input())
d = int(input())
h = 0
for i in range(1,d+1):
if i%k!=0 and i%l!=0 and i%m!=0 and i%n!=0:
h+=1
print(d-h)
4 changes: 4 additions & 0 deletions codeforce/Is your horseshoe on the other hoof.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
s = input().split()
S = list(s)
m = 4 - int(len(set(S)))
print(m)
Binary file added codeforce/List of the problems.xlsx
Binary file not shown.
24 changes: 24 additions & 0 deletions codeforce/Magnets.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include<iostream>
using namespace std;
int main()
{
int n;cin>>n;
int gp=1;
string temp,value;
for (int i =0;i<n;i++)
{
cin>>value;
if (i ==0)
{
temp=value;
continue;
}
if (temp[1] == value[0])
{
++gp;
}
temp=value;

}
cout<<gp;
}
19 changes: 19 additions & 0 deletions codeforce/Mahmoud and Longest Uncommon Subsequence.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <bits/stdc++.h>
using namespace std;
int main()
{
string a,b;
cin>>a>>b;
if (a==b)
{
cout<<-1;
}
else if (a.length()==b.length() && a!=b)
{
cout<<a.length();
}
else
{
cout<<max(a.length(),b.length());
}
}
9 changes: 9 additions & 0 deletions codeforce/Minutes Before the New Year.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
n = int(input())
t = 1440
l = []
for i in range(n):
h,m = map(int,input().split())
z = (h*60)+m
a = t-z
l.append(a)
print(*l,sep='\n')S
7 changes: 7 additions & 0 deletions codeforce/Next Round.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
n,k = map(int,input().split())
l = list(input().split())
c = 0
for i in l :
if int(i)!= 0 and int(i)>=int(l[k-1]) :
c=c+1
print(c)
17 changes: 17 additions & 0 deletions codeforce/Pangram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def Pangram(s):
L = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
s = s.upper()
z = set(s)
T = []
for i in L:
if i in z:
T.append(True)

if len(T) == 26 :
return "Yes"
else:
return "No"

n = int(input())
s = input()
print(Pangram(s))
11 changes: 11 additions & 0 deletions codeforce/Petya and Strings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def retur(s1,s2):
if s1 > s2:
return 1
elif s1 < s2:
return -1
else:
return 0

st1 = str(input().lower())
st2 = str(input().lower())
print(retur(st1,st2))
11 changes: 11 additions & 0 deletions codeforce/Phone Numbers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
t = int(input())
l = []
for i in range(t):
a,b = map(str,input().split())
b = list(b)
s = 0
for i in b :
s = s+int(i)
if s%2 == 0:
l.append(a)
print(*l,sep='\n')
24 changes: 24 additions & 0 deletions codeforce/Police recruits.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include<iostream>
using namespace std;
int main()
{
int n;cin>>n;
int sum=0,c=0;
int arr[n];
for (int i=0;i<n;i++)
{
cin>>arr[i];
}
for (int i=0;i<n;i++)
{
if (sum +arr[i] <0)
{
c++;
}
else
{
sum+=arr[i];
}
}
cout<<c;
}
8 changes: 8 additions & 0 deletions codeforce/Presents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
size = int(input())
num = list(input().split())
l=[]
for i in range(1,size+1):
l.append(int(num.index(str(i)))+1)

print(*l,end=" ")

Loading