=INT(A1/8) & "天" & ROUND(MOD(A1,8),0) & "小时"对这条函数式进行优化,对余数四舍五入添加到天数中
时间: 2024-05-30 19:09:18 浏览: 14
可以使用以下函数式进行优化:
=INT(A1/8)+ROUND(MOD(A1,8)/8,1) & "天" & ROUND(MOD(A1,8),0) & "小时"
其中,ROUND(MOD(A1,8)/8,1) 表示将余数除以8后再四舍五入,并加到天数中。注意,这里使用了第二个参数为1的ROUND函数,表示保留一位小数,避免出现多余的小数位。
相关问题
int main() { char a; int i = 0; int number = 0; //数字个数 int space = 0; //空格个数 int letters = 0; //字母个数 int other = 0; //其他个数 while((a=getchar())&&a!='\n') { if(a >= '0' && a <= '9') { number++; }else if(a == ' ') { space ++; }else if((a >= 'a' && a <= 'z') || (a >= 'A' && a <= 'Z')) { letters ++; }else { other++; } } printf("英文字母个数为:%d\n", letters ); printf("数字个数为:%d\n", number); printf("空格个数为:%d\n", space ); printf("其他个数为:%d\n", other); return 0; } 请用c++代码翻译
#include <iostream>
using namespace std;
int main() {
char a;
int i = 0;
int number = 0; //数字个数
int space = 0; //空格个数
int letters = 0; //字母个数
int other = 0; //其他个数
while((a=getchar())&&a!='\n') {
if(a >= '0' && a <= '9') {
number++;
} else if(a == ' ') {
space ++;
} else if((a >= 'a' && a <= 'z') || (a >= 'A' && a <= 'Z')) {
letters ++;
} else {
other++;
}
}
cout << "英文字母个数为:" << letters << endl;
cout << "数字个数为:" << number << endl;
cout << "空格个数为:" << space << endl;
cout << "其他个数为:" << other << endl;
return 0;
}
#include<stdio.h> void getFiveNum(int a[], FILE *fp); void position(int a[], int num, FILE *fp); int main() { FILE *fp = fopen("dict.dic", "r"); int a[6]; a[0] = 5; getFiveNum(a, fp); int num; scanf("%d", &num); position(a, num, fp); fclose(fp); return 0; } void getFiveNum(int a[], FILE fp) { int ch; for (int i = 1; i <= 5; i++) { ch = fgetc(fp); a[i] = 0; while (ch != 10) { a[i] = a[i] * 10 + (ch - '0'); ch = fgetc(fp); } } } void position(int a[], int num, FILE fp) { int ch, not1 = 0, not2 = 0, line = a[num], enter = 5, chNext; while (enter < a[num - 1]) { ch = fgetc(fp); if (ch == 10) enter++; } ch = fgetc(fp); chNext = fgetc(fp); while (enter < line) { if (not2 == 0 && ch == '/' && chNext == '/') { not1 = 1; }else if (not1 == 0 && ch == '/' && chNext == '') { not2 = 1; }else if (not1 == 1 && chNext == 10) { not1 = 0; ch = chNext; chNext = fgetc(fp); }else if (not2 && ch == '' && chNext == '/') { not2 = 0; ch = chNext; chNext = fgetc(fp); if (chNext == 10) { enter++; } ch = chNext; chNext = fgetc(fp); if (chNext == 10) enter++; } if (not1 == 0 && not2 == 0) { printf("%c", ch); } ch = chNext; chNext = fgetc(fp); if (chNext == 10) { enter++; }else if (chNext == EOF) { if (not1 == 0 && not2 == 0) { printf("%c", ch); break; } else { break; } } } if (not1 == 0 && not2 == 0 && chNext == 10) { printf("%c", ch); } }将子函数并到主函数里
以下是将子函数并到主函数的代码:
#include<stdio.h>
int main() {
FILE *fp = fopen("dict.dic", "r");
int a[6];
a[0] = 5;
int ch, not1 = 0, not2 = 0, line = a[num], enter = 5, chNext;
for (int i = 1; i <= 5; i++) {
ch = fgetc(fp);
a[i] = 0;
while (ch != 10) {
a[i] = a[i] * 10 + (ch - '0');
ch = fgetc(fp);
}
}
int num;
scanf("%d", &num);
while (enter < a[num - 1]) {
ch = fgetc(fp);
if (ch == 10) enter++;
}
ch = fgetc(fp);
chNext = fgetc(fp);
while (enter < line) {
if (not2 == 0 && ch == '/' && chNext == '/') {
not1 = 1;
} else if (not1 == 0 && ch == '/' && chNext == '') {
not2 = 1;
} else if (not1 == 1 && chNext == 10) {
not1 = 0;
ch = chNext;
chNext = fgetc(fp);
} else if (not2 && ch == '' && chNext == '/') {
not2 = 0;
ch = chNext;
chNext = fgetc(fp);
if (chNext == 10) {
enter++;
}
ch = chNext;
chNext = fgetc(fp);
if (chNext == 10) enter++;
}
if (not1 == 0 && not2 == 0) {
printf("%c", ch);
}
ch = chNext;
chNext = fgetc(fp);
if (chNext == 10) {
enter++;
} else if (chNext == EOF) {
if (not1 == 0 && not2 == 0) {
printf("%c", ch);
break;
} else {
break;
}
}
}
if (not1 == 0 && not2 == 0 && chNext == 10) {
printf("%c", ch);
}
fclose(fp);
return 0;
}
注意,将子函数并到主函数的代码,需要将子函数中的参数 FILE *fp 删除,并将 fp 声明为全局变量,否则会编译报错。