题意:求给出的几组数字之和
#include
#include
char s[105];
int num[105];
int t[10000] = {0};
int main() {
int i, j, l, flag;
/*freopen("D:\\in.txt", "r", stdin);*/
while (scanf("%s", s) != EOF) {
l = strlen(s);
memset(num, 0, sizeof(num));
for (i = 0; i < l; i++)
num[l - i - 1] = s[i] - '0';
for (i = 0; i < l; i++)
t[i] += num[i];
for (i = 0; i < 10000; i++) {
t[i+1] += (t[i] / 10);
t[i] %= 10;
}
}
flag = 0;
for (i = 10000 - 1; i>=0; i--) {
if (flag)
printf("%d", t[i]);
else if (t[i]) {
printf("%d", t[i]);
flag = 1;
}
}
printf("\n");
return 0;
}
题意:求出所给的每两组数字的乘积
#include
#include
char n1[300], n2[300];
int x[300], y[300], mul[100000];
int main() {
int i, j, c;
/*freopen("D:\\in.txt", "r", stdin);*/
while (scanf("%s%s", n1, n2) != EOF) {
int l1 = strlen(n1);
int l2 = strlen(n2);
memset(x, 0, sizeof(x));
memset(y, 0, sizeof(y));
memset(mul, 0, sizeof(mul));
for (i = 0; i < l1; i++)
x[l1 - 1 - i] = n1[i] - '0';
for (i = 0; i < l2; i++)
y[l2 - 1 - i] = n2[i] - '0';
for (i = 0; i < l1; i++) {
c = i;
for (j = 0; j < l2; j++) {
mul[c] += x[i] * y[j];
mul[c + 1] += mul[c] / 10;
mul[c] %= 10;
c++;
}
}
int flag = 0;
for (i = 1000 - 1; i >= 0; i--) {
if (flag)
printf("%d", mul[i]);
else if (mul[i]) {
printf("%d", mul[i]);
flag = 1;
}
}
if (flag == 0)
printf("0");
printf("\n");
}
return 0;
}
题意:判断所给的两个加数以及和是否超过了int型所能存储的范围
#include
#include
#include
int main() {
int max = pow(2.0, 31) - 1;
char n1[310], n2[310];
char sign;
double a, b;
/*freopen("D:\\in.txt", "r", stdin);*/
while (scanf("%s %c %s", n1, &sign, n2) != EOF) {
printf("%s %c %s\n", n1, sign, n2);
a = atof(n1);
b = atof(n2);
if (a > max) printf("first number too big\n");
if (b > max) printf("second number too big\n");
if (sign == '+' && a + b > max) printf("result too big\n");
else if (sign == '*' && a * b > max) printf("result too big\n");
}
return 0;
}
题意:求出所给实数的次方
#include
#include
char d[10];
int mul[30000], num[10], m[30000];
int main() {
int i, j, k, n, t, temp;
/*freopen("D:\\in.txt", "r", stdin);*/
while (scanf("%s%d", d, &n) != EOF) {
memset(mul, 0, sizeof(mul));
memset(num, 0, sizeof(num));
k = 5;
for (i = 0; i < 6; i++) {
if (d[i] == '.')
temp = (5 - i) * n;
else num[--k] = d[i] - '0';
}
for (i = 0; i < 5; i++)
mul[i] = num[i];
for (i = 1; i < n; i++) {
memset(m, 0, sizeof(m));
for (j = 0; j < 5; j++) {
int l = j;
for (k = 0; k < 29999; k++) {
m[l] += mul[k] * num[j];
m[l + 1] += m[l] / 10;
m[l] %= 10;
l++;
}
}
for (j = 0; j < 29999; j++)
mul[j] = m[j];
}
for (i = 29999; i >= 0; i--)
if (mul[i] || i == temp) break;
for (j = 0; j <= i; j++)
if (mul[j]) break;
for (t = i; t >= j; t--) {
if (temp == t && t == i) {
if (mul[t]) printf("%d.", mul[t]);
else printf(".");
continue;
}
printf("%d", mul[t]);
if (temp == t && t != i) printf(".");
}
printf("\n");
}
return 0;
}
题意:求商
#include
#include
#define MAX 10000
long int quo[MAX] = {0};
char d[MAX] = {0};
int main() {
long int i, l, count, temp, t;
int n, flag;
char sign;
/*freopen("D:\\in.txt", "r", stdin);*/
while (scanf("%s %c %d", d, &sign, &n) != EOF) {
temp = flag = count = 0;
for (i = 0; i < strlen(d); i++) {
temp = temp * 10 + d[i] - '0';
t = temp / n;
if (t != 0 || t == 0 && flag == 1) {
quo[count++] = t;
flag = 1;
}
temp %= n;
}
if (sign == '%') printf("%d\n", temp);
else {
if (count == 0) printf("0");
else for (i = 0; i < count; i++)
printf("%d", quo[i]);
printf("\n");
}
memset(quo, 0, sizeof(quo));
memset(d, 0, sizeof(d));
}
return 0;
}