Monday, September 16, 2019

Codeforce A. Collecting Beats is Fun

  1. #include< bits/stdc++.h >
  2. using namespace std;
  3. int main(){
  4. int k;
  5. char a;
  6. cin >> k;
  7. int ar[10] = {0};
  8. for(int i = 0; i < 16; i++){
  9. cin >> a;
  10. ar[a]++;
  11. }
  12. for(int i = 1; i < 10; i++)
  13. if(ar[i+'0'] > 2*k) return cout << "NO\n", 0;
  14. cout << "YES\n";
  15. return 0;
  16. }

Codeforce A. Levko and Table

  1. #include< iostream >
  2. using namespace std;
  3. int main()
  4. {
  5. int n, k;
  6. cin >> n >> k;
  7. for(int i = 0; i < n; i++) {
  8. for(int j = 0; j < n; j++) {
  9. cout << ((i == j)? k : 0 ) << " ";
  10. }
  11. cout << endl;
  12. }
  13. return 0;
  14. }

Codeforce A. Vasya and Digital Root

  1. #include< iostream >
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int k, d;
  7. cin >> k >> d;
  8. if(d == 0 and k > 1) return cout << "No solution\n", 0;
  9. cout << d ;
  10. while(--k) cout << 0 ;
  11. return 0;
  12. }

Codeforce A. Two Bags of Potatoes

  1. #include< iostream >
  2. using namespace std;
  3. int main()
  4. {
  5. int y, k, n;
  6. cin >> y >> k >> n;
  7. int x = k - y%k;
  8. if(x+y > n) return cout << -1 << endl , 0;
  9. for(int i = x ; i <= n-y; i+=k)
  10. cout << i << " ";
  11. return 0;
  12. }

Codeforce A. The Child and Homework

  1. #include< iostream >
  2. #include< cstdio >
  3. #include< algorithm >
  4.  
  5. using namespace std;
  6.  
  7. string o[4];
  8.  
  9. int main() {
  10.  
  11. int maxlength = 0, minlength = 110, maxindex = 0, minindex = 0;
  12.  
  13. int c[4];
  14.  
  15. for (int i = 0; i < 4; i++) {
  16. getline(cin, o[i]);
  17. c[i] = o[i].length() - 2;
  18. }
  19.  
  20. sort(c, c + 4);
  21.  
  22. bool hasMax = c[3] >= c[2] * 2;
  23. bool hasMin = c[0] <= c[1] / 2;
  24.  
  25. if (hasMax == hasMin) {
  26. cout << "C";
  27. } else if (hasMin) {
  28. for (int i = 0; i < 4; i++) {
  29. if (c[0] + 2 == o[i].length()) {
  30. cout << o[i].at(0);
  31. }
  32. }
  33. } else if (hasMax) {
  34. for (int i = 0; i < 4; i++) {
  35. if (c[3] + 2 == o[i].length()) {
  36. cout << o[i].at(0);
  37. }
  38. }
  39. }
  40.  
  41. return 0;
  42. }

Codeforce A. Soroban

    1. #include < bits/stdc++.h >
    2. using namespace std;
    3. int main()
    4. {
    5. int n;
    6. cin>>n;
    7. if(!n){
    8. cout<<"O-|-OOOO\n";
    9. return 0;
    10. }
    11. while(n){
    12. int m=n%10;
    13. n/=10;
    14. string s="--|OOOOO";
    15. if(m>=5)s[1]='O';
    16. else s[0]='O';
    17. s[m%5+3]='-';
    18. cout<<s<<endl;
    19. }
    20. }

Sunday, September 15, 2019

Uri 2787 - Chess

#include< iostream >

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    cout << (((n + (m-1))%2 == 0)? 0 : 1 ) << endl;
    return 0;
}

Uri 1495 - Football

#include < bits/stdc++.h >
using namespace std;

vector< int > v;

bool compare(int a, int b) { return (a > b); }

int main(int argc, char const *argv[])
{
int n, g, s, r, c, i, sz;
bool b;

while(scanf("%d %d", &n, &g) == 2)
{
c = 0;
v.clear();

for (i = 0; i < n; ++i)
{
scanf("%d %d", &s, &r);
if(s > r) c += 3;
else v.push_back(s - r);
}

sort(v.begin(), v.end(), compare);
sz = v.size();
b = false;

for (i = 0; i < sz; ++i)
{
if(b){
if(v[i] == 0) c++;
else break;
}else{
if(g <= 0) b = true;

if((1 - v[i]) <= g){
g -= (1 - v[i]);
c += 3;
}else if((0 - v[i]) == g){
c++;
g -= (0-v[i]);
}else{
b = true;
}
}
}

printf("%d\n", c);
}

return 0;
}

1069 - Diamonds and Sand

#include< bits/stdc++.h >
using namespace std;

int main()
{
    int n;
    string s;
    cin  >>  n;

    while(n--) {
        stack< char >st;
        int ans = 0;
        cin  >>  s;
        for(auto ch: s) {
            if(ch == '<') st.push(ch);
            else if( !st.empty() and ch == '>' ) {
                ans++;
                st.pop();
            }
        }
        cout << ans << endl;
    }

    return 0;
}

AtCoder Beginner Contest 136(A - Transfer)

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int a, b, c;
  6. cin >> a >> b >> c;
  7. cout << ((a-b > c)? 0 : c-(a-b)) << endl;
  8. return 0;
  9. }

AtCoder Beginner Contest 136(B - Uneven Numbers)

  1. #include< bits/stdc++.h >
  2. using namespace std;
  3. int main(){
  4. int n, ans = 0;
  5. cin >> n;
  6. for(int i = 1; i <= n; i++) {
  7. string s;
  8. stringstream ss;
  9. ss << i;
  10. ss >> s;
  11. if(s.size()%2) ans++;
  12. }
  13. cout << ans << endl;
  14. return 0;
  15. }

AtCoder Beginner Contest 136(C - Build Stairs)

  1. #include< bits/stdc++.h >
  2. using namespace std;
  3. int main()
  4. {
  5. int n, m;
  6. int vc[100001];
  7. cin >> n;
  8. for(int i = 0; i < n; i++){
  9. cin >> vc[i];
  10. }
  11. for(int i = n - 1; i > 0; i--) {
  12. if(vc[i] < vc[i-1]) vc[i - 1] -= 1;
  13. }
  14. for(int i = 1; i < n; i++) {
  15. if(vc[i-1] > vc[i]) return cout << "No" << endl, 0;
  16. }
  17. cout << "Yes" << endl;
  18. return 0;
  19. }

Saturday, September 14, 2019

583 Digit Generator in cpp solution

#include< bits/stdc++.h > using namespace std;
int main()
{
ios::sync_with_stdio(false);cin.tie(0);
int n, k;
cin >> n;
while(n--) {
cin >> k;
int ans = 0, res = 0;
int range = (k < 10) ? 9 : (k < 100)? 18: (k < 1000)? 27: (k < 10000)? 45 : 60;
for(int i = k - range; i <= k; i++) {
int num = i, sum = i;
while( num != 0) {
sum += num%10;
num /= 10;
}
if(sum == k) {
ans = 1;
res = i;
break;
}
}
cout << ((ans)? res : 0 ) << endl;
}
return 0;
}