#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespace std; #define pf printf #define sf scanf #define loop(i, n) for(i=0; i<(n); i++) #define MAX 100 int n; string s, s1, minS; bool min(string s1, string s2) { int i; int check = false; loop(i, n) { if(s1[i]==s2[i]) continue; else if(s1[i]>s2[i]) { check = true; break; } else { check = false; break; } } return check; } void addOne() { int i; loop(i, n) { if(s1[i]=='9') s1[i] = '0'; else s1[i]++; } } void rightShift() { s = s.substr(n-1,1)+ s.substr(0,n-1); } int main() { int i, j; cin >> n; cin >> s; minS = s; loop(i, n) { s1 = s; loop(j, 9) { addOne(); if(min(minS, s1)) minS = s1; } rightShift(); if(min(minS, s)) minS = s; } cout << minS << endl; return 0; }
Thursday, May 7, 2015
496B - Secret Combination (Codeforces)
499B - Lecture (Codeforces)
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #include<map> using namespace std; #define pf printf #define sf scanf #define loop(i, n) for(i=0; i<(n); i++) #define MAX 100 map<string, string> mp; int main() { //freopen("in.txt","r",stdin); int n, m; string s1, s2; cin >> n >> m; while(m--) { cin >> s1 >> s2; if(s1.length()>s2.length()) mp[s1] = s2; else mp[s1] = s1; } while(n--) { cin >> s1; cout << mp[s1] << " "; } cout << endl; return 0; }
508B - Anton and currency you all know (Codeforces)
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespace std; #define pf printf #define sf scanf #define loop(i, n) for(i=0; i<(n); i++) #define MAX 100 int main() { string s; int i, len; int index, temp, odd; int flag=0; cin >> s; len = s.length(); odd = s[len-1]-'0'; for(i=len-1; i>=0; i--) { temp = s[i]-'0'; if(temp%2==0) { flag++; if(flag==1) { index = i; } if(odd>temp) { index = i; } } } if(flag==0) cout <<"-1" << endl; else { swap(s[index], s[len-1]); cout << s << endl; } return 0; }
Friday, May 1, 2015
465A - inc ARG
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define sf scanf
#define pf printf
#define loop(i, n) for(i=0; i<(n) ; i++)
#define MAX 100
int main()
{
string s;
int n, i;
cin >> n;
cin >> s;
int c = 1;
int count = 0;
loop(i, n)
{
if(s[i]=='0' && c==1)
{
count++;
c = 0;
}
else if(s[i]=='1' && c==1)
{
count++;
c = 1;
}
else
break;
}
cout << count << endl;
return 0;
}
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define sf scanf
#define pf printf
#define loop(i, n) for(i=0; i<(n) ; i++)
#define MAX 100
int main()
{
string s;
int n, i;
cin >> n;
cin >> s;
int c = 1;
int count = 0;
loop(i, n)
{
if(s[i]=='0' && c==1)
{
count++;
c = 0;
}
else if(s[i]=='1' && c==1)
{
count++;
c = 1;
}
else
break;
}
cout << count << endl;
return 0;
}
448A - Rewards (Codeforces)
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespace std; #define pf printf #define sf scanf #define loop(i, n) for(i=0; i<n; i++) #define MAX 100 int main() { int n; float a1, a2, a3, slv_a; float b1, b2, b3, slv_b; cin >> a1 >> a2 >> a3; cin >> b1 >> b2 >> b3; cin >> n; slv_a = ceil((a1+a2+a3)/5); slv_b = ceil((b1+b2+b3)/10); if((slv_a+slv_b)<=n) cout <<"YES" << endl; else cout << "NO" << endl; return 0; }
450A - Jzzhu and Children (Codeforces)
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespace std; #define pf printf #define sf scanf #define loop(i, n) for(i=0; i<n; i++) #define MAX 105 int a[MAX], index[MAX], step[MAX], step2[MAX], small[MAX]; float big[MAX]; int main() { int n, m, ans, temp; int i, j, s=1, b=1, s2=1, sm=1; ans =0; temp =0; cin >> n >> m; i = 1; for(j=1; j<=n; j++) { cin >> a[j]; small[sm++] = a[j]; if(a[j]>m) { big[b] = a[j]; index[i++] = j; step[s] = ceil(big[b]/m); step2[s2++] = step[s]; b++; s++; } } if(b>1) { sort(step2, step2+s2); for(j=1; j<s; j++) { if(step2[s2-1]==step[j]) { temp = j; } } ans = index[temp]; cout << ans << endl; } else { i =1; for(j=1; j<=n ;j++) { if(small[sm-1]==a[j]) { index[i++] = j; } } cout << index[i-1] << endl; } return 0; }
451A - Game With Sticks (Codeforces)
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespace std; #define pf printf #define sf scanf #define loop(i, n) for(i=0; i<n; i++) #define MAX 100 int min(int n, int m) { if(n>m) return m; else return n; } int main() { int n, m; cin >> n >> m; int temp = min(n, m); if(temp & 1) cout << "Akshat" << endl; else cout << "Malvika" << endl; return 0; }
Subscribe to:
Posts (Atom)
Compare equality of two string in C
#include <stdio.h> #include<string.h> int main() { char* country = "Bangladesh"; char* country2; ...
-
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespac...
-
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<cstring> #include<ve...
-
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> using namespace std; #define pf printf ...