diff --git a/Domains/CompetitiveProgramming/Programs/C++/AntonAndDanik.cpp b/Domains/CompetitiveProgramming/Programs/C++/AntonAndDanik.cpp new file mode 100644 index 00000000..1cca6add --- /dev/null +++ b/Domains/CompetitiveProgramming/Programs/C++/AntonAndDanik.cpp @@ -0,0 +1,72 @@ +/* +Problem: Anton and Danik +Platform: Codeforces +Problem Code: 734A +Difficulty: Easy (800 rated) +Link: https://codeforces.com/problemset/problem/734/A + +Anton likes to play chess, and so does his friend Danik. + +Once they have played n games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie. + +Now Anton wonders, who won more games, he or Danik? Help him determine this. + +Input +The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of games played. + +The second line contains a string s, consisting of n uppercase English letters 'A' and 'D' — the outcome of each of the games. The i-th character of the string is equal to 'A' if the Anton won the i-th game and 'D' if Danik won the i-th game. + +Output +If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output. + +If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output. + +If Anton and Danik won the same number of games, print "Friendship" (without quotes). + +Examples: + +Input: +6 +ADAAAA +Output: +Anton + +Input: +7 +DDDAADA +Output: +Danik + +Input: +6 +DADADA +Output: +Friendship + +Approach: +1. Calculate the number of A's, and compare it with the number of D's +2. return Anton if A > D and Danik if A < D and Friendship if A = D. + +Time Complexity: O(n) +Space Complexity: O(1) + +Contributor: SamaKool +*/ + +#include +using namespace std; + +int main(){ + int n; + string s; + cin >> n; + cin >> s; + int Acnt = 0; + for (int i = 0; i < n; i++){ + if(s[i] == 'A') Acnt++; + } + if(Acnt > n - Acnt) cout<<"Anton"; + else if(Acnt < n - Acnt) cout<<"Danik"; + else cout<<"Friendship"; + return 0; +} \ No newline at end of file