- #include< bits/stdc++.h >
- using namespace std;
- int main(){
- int k;
- char a;
- cin >> k;
- int ar[10] = {0};
- for(int i = 0; i < 16; i++){
- cin >> a;
- ar[a]++;
- }
- for(int i = 1; i < 10; i++)
- if(ar[i+'0'] > 2*k) return cout << "NO\n", 0;
- cout << "YES\n";
- return 0;
- }
Monday, September 16, 2019
Codeforce A. Collecting Beats is Fun
Codeforce A. Levko and Table
- #include< iostream >
- using namespace std;
- int main()
- {
- int n, k;
- cin >> n >> k;
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < n; j++) {
- cout << ((i == j)? k : 0 ) << " ";
- }
- cout << endl;
- }
- return 0;
- }
Codeforce A. Vasya and Digital Root
- #include< iostream >
- using namespace std;
- int main()
- {
- int k, d;
- cin >> k >> d;
- if(d == 0 and k > 1) return cout << "No solution\n", 0;
- cout << d ;
- while(--k) cout << 0 ;
- return 0;
- }
Codeforce A. Two Bags of Potatoes
- #include< iostream >
- using namespace std;
- int main()
- {
- int y, k, n;
- cin >> y >> k >> n;
- int x = k - y%k;
- if(x+y > n) return cout << -1 << endl , 0;
- for(int i = x ; i <= n-y; i+=k)
- cout << i << " ";
- return 0;
- }
Codeforce A. The Child and Homework
- #include< iostream >
- #include< cstdio >
- #include< algorithm >
- using namespace std;
- string o[4];
- int main() {
- int maxlength = 0, minlength = 110, maxindex = 0, minindex = 0;
- int c[4];
- for (int i = 0; i < 4; i++) {
- getline(cin, o[i]);
- c[i] = o[i].length() - 2;
- }
- sort(c, c + 4);
- bool hasMax = c[3] >= c[2] * 2;
- bool hasMin = c[0] <= c[1] / 2;
- if (hasMax == hasMin) {
- cout << "C";
- } else if (hasMin) {
- for (int i = 0; i < 4; i++) {
- if (c[0] + 2 == o[i].length()) {
- cout << o[i].at(0);
- }
- }
- } else if (hasMax) {
- for (int i = 0; i < 4; i++) {
- if (c[3] + 2 == o[i].length()) {
- cout << o[i].at(0);
- }
- }
- }
- return 0;
- }
Codeforce A. Soroban
- #include < bits/stdc++.h >
- using namespace std;
- int main()
- {
- int n;
- cin>>n;
- if(!n){
- cout<<"O-|-OOOO\n";
- return 0;
- }
- while(n){
- int m=n%10;
- n/=10;
- string s="--|OOOOO";
- if(m>=5)s[1]='O';
- else s[0]='O';
- s[m%5+3]='-';
- cout<<s<<endl;
- }
- }
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;
}
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;
}
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;
}
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)
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int a, b, c;
- cin >> a >> b >> c;
- cout << ((a-b > c)? 0 : c-(a-b)) << endl;
- return 0;
- }
AtCoder Beginner Contest 136(B - Uneven Numbers)
- #include< bits/stdc++.h >
- using namespace std;
- int main(){
- int n, ans = 0;
- cin >> n;
- for(int i = 1; i <= n; i++) {
- string s;
- stringstream ss;
- ss << i;
- ss >> s;
- if(s.size()%2) ans++;
- }
- cout << ans << endl;
- return 0;
- }
AtCoder Beginner Contest 136(C - Build Stairs)
- #include< bits/stdc++.h >
- using namespace std;
- int main()
- {
- int n, m;
- int vc[100001];
- cin >> n;
- for(int i = 0; i < n; i++){
- cin >> vc[i];
- }
- for(int i = n - 1; i > 0; i--) {
- if(vc[i] < vc[i-1]) vc[i - 1] -= 1;
- }
- for(int i = 1; i < n; i++) {
- if(vc[i-1] > vc[i]) return cout << "No" << endl, 0;
- }
- cout << "Yes" << endl;
- return 0;
- }
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; | |
} |
Subscribe to:
Posts (Atom)