# Codeforces 946a,b,c

• 2018-03-14
• 510
• 0
• 0

## · Codeforces 946a

### Origin：http://codeforces.com/problemset/problem/946/A

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

int main()
{
int n, ans = 0, t;
scanf("%d", &n);
for(int i = 0; i < n; i++)
{
scanf("%d", &t);
ans += abs(t);
}
printf("%d\n", ans);

return 0;
}
``````

## · Codeforces 946b

### Origin：http://codeforces.com/problemset/problem/946/B

1. If a = 0 or b = 0, end the process. Otherwise, go to step 2;
2. If a ≥ 2·b, then set the value of a to a - 2·b, and repeat step 1. Otherwise, go to step 3;
3. If b ≥ 2·a, then set the value of b to b - 2·a, and repeat step 1. Otherwise, end the process.

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

int main()
{
long long a, b, t;
scanf("%lld%lld", &a, &b);
while(1)
{
if (a == 0 || b == 0 || a < 2 * b && b < 2 * a) break;
a = a % (2 * b);
if (a == 0 || b < 2 * a) break;
b = b % (2 * a);
}
printf("%lld %lld\n", a, b);

return 0;
}
``````

## · Codeforces 946c

### Origin：http://codeforces.com/problemset/problem/946/C

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

int main()
{
char s[100005];
scanf("%s", s);
int len = strlen(s), pos = 0;
char ch = 'a';
for (int i = 0; i < len; i++) { if (ch == 'z' + 1) break; if (s[i] > ch) continue;
s[i] = ch++;
}
if (ch == 'z' + 1) printf("%s\n", s);
else printf("-1\n");

return 0;
}
``````