#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; }
Thursday, May 7, 2015
508B - Anton and currency you all know (Codeforces)
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; }
454A. Little Pony and Crystal Mine(Codeforces)
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespace std; #define pf printf #define sf scanf #define MAX 105 char a[MAX][MAX]; int main() { int i , j, n, temp=0, mid=0; memset(a, '*', sizeof(a)); sf("%d", &n); mid = (n-1)/2; for(i=0; i<=n; i++) { for(j=mid; j<=mid+i; j++) { a[i][j] = 'D'; } for(j=mid; j>=mid-i; j--) { a[i][j] = 'D'; } } for(i=0; i<=mid; i++) { for(j=0; j<n; j++) { cout << a[i][j]; } cout << endl; } for(i=mid-1; i>=0; i--) { for(j=0; j<n; j++) { cout << a[i][j]; } cout << endl; } return 0; }
UVa 11936. The Lazy Lumberjacks
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define sf scanf
#define pf printf
#define PI 2*acos(0.0)
int main()
{
int t;
sf("%d",&t);
while(t--)
{
ll a, b, c;
sf("%lld%lld%lld", &a, &b, &c);
if(a+b>c && b+c>a && a+c>b)
pf("OK\n");
else
pf("Wrong!!\n");
}
return 0;
}
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define sf scanf
#define pf printf
#define PI 2*acos(0.0)
int main()
{
int t;
sf("%d",&t);
while(t--)
{
ll a, b, c;
sf("%lld%lld%lld", &a, &b, &c);
if(a+b>c && b+c>a && a+c>b)
pf("OK\n");
else
pf("Wrong!!\n");
}
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 ...