#include1101: 逆序数字(函数专题) Clong long int t=1,a,b; long fact(long n) { t = 1; for (int i = 1; i <= n; i++) t *= i; return t; } int m, k; int main() { scanf("%d%d", &m, &k); a = fact(m - k); b = fact(k); t = fact(m); printf("%lld", t / (a*b)); } ## 1101: 逆序数字(函数专题) #### C ```c #include #include int inverse(int n) { int i,b, a,t,m,c; t = 0; a = log10(n)+1; for (i = 1; i <= a; i++) { m = n; b = n / pow(10, a - i); b = b % 10; t += b * pow(10, i - 1); } return t; } int main() { int n,q,p; scanf("%d", &n); q = inverse(n); printf("%d", q + n); }
#include1102: 火车票退票费计算(函数专题) C#include int inverse(int n) { int i,b, a,t,m,c; t = 0; a = log10(n)+1; for (i = 1; i <= a; i++) { m = n; b = n / pow(10, a - i); b = b % 10; t += b * pow(10, i - 1); } return t; } int main() { int n,q,p; scanf("%d", &n); q = inverse(n); printf("%d", q + n); }
#include1103: 平均学分绩点(函数专题) Cdouble CancelFee(double price) { price = price * 2; price = price * 0.05+0.5; price = (int)price; return price / 2; } int main() { double a; scanf("%lf", &a); a = CancelFee(a); printf("%.1f",a); }
#include1104: 求因子和(函数专题) Cint point(int p) { if (p >= 50) { p = p - 50; p = p / 10; return p; } else return 0; } int main() { int n, i, p,a,t,A=0; double m=0; scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%d %d", &a, &p); p = point(p); t = p * a; m += t; A += a; } m = m / A; printf("%.1f", m); }
#include1105: 判断友好数对(函数专题) Cint sum; int FacSum(int n) { for (int i = 1; i < n; i++) { if (n%i == 0) sum += i; } return sum; } int main() { int n; scanf("%d", &n); n = FacSum(n); printf("%d", n); }
#include1106: 回文数(函数专题) Cint sum; int FacSum(int n) { sum = 0; for (int i = 1; i < n; i++) { if (n%i == 0) sum += i; } return sum; } int main() { int n,m,a,b,t=0; scanf("%d%d", &n,&m); for (; n <= m; n++) { a = FacSum(n); b = FacSum(a); if (n == b&&n!=a) { printf("%d %dn", n, a); t = 1; n = a; } } if (t == 0) printf("No answer"); }
#include1107: 回文数猜想(函数专题) C#include int huiwen(int a) { int b,c,d,e,t=0,m,n; b=log10(a); m=b; for(int i=1;i<=(b+1)/2;i++,m--) { c=a/pow(10,m); c=c%10; e=pow(10,i); d=a%e; n=pow(10,b-m); d=d/n; if(d==c) continue; else { t=1; break; } } if(t!=1) return 1; else return 0; } int main() { int a,b,t; scanf("%d%d",&a,&b); for(;a<=b;a++) { t=huiwen(a); if(t==1) printf("%d ",a); else continue; } }
#include1108: 打印数字图形(函数专题) C#include int huiwen(int a) { int sum=0; while (a) { sum = sum * 10 + a % 10; a /= 10; } return sum; } int main() { int n, m; scanf("%d", &n); printf("%d ",n); m = huiwen(n); while(n != m) { m = huiwen(n); if(m==n) { break; } n += m; printf("%d ", n); } }
#include1109: 数根(函数专题) Cvoid PrintLine(int m, int n) { int t = 0; for (int p = 1; p < n; p++) printf(" "); for (int i = 1; i <= m; i++) { if (t == 0) printf("%d", i); else if (t == 1) printf("%d", i - m); if (i == m) t = 1; } for (int i = m - 1; i >= 1; i--) { printf("%d", i); } } int main() { int a, b, c, t = 0, n; scanf("%d", &a); for (int i = 1; i <= a; i++) { if (t == 0) n = a - i+1; else n =-1*(a-i)+1; if (i == a) t = 1; PrintLine(i, n); printf("n"); } t = 0; for (int i = a-1; i >=1; i--) { if (t == 0) n = a - i + 1; else n = -1 * (a - i) + 1; if (i == a) t = 1; PrintLine(i, n); printf("n"); } }
#include1110: 最近共同祖先(函数专题) C#include int digitSum(int n) { int a,t=0; a = log10(n) + 1; for (int i = 1; i <= a; i++) { t += n % 10; n /= 10; } return t; } int main() { int n; scanf("%d", &n); while(n>=10) n = digitSum(n); printf("%d", n); }
#include1111: 多个整数的逆序输出(函数专题) Cint common(int x, int y) { if (x == y) return x; if (x > y) common(x / 2, y); else common(x, y / 2); } int main() { int x, y,t; scanf("%d%d", &x, &y); t=common(x, y); printf("%d",t); }
#include1112: 进制转换(函数专题) Cvoid inverse(int n) { int a; scanf("%d", &a); if (n > 1) { inverse(n - 1); printf("%d ", a); } if (n == 1) printf("%d ", a); } int main() { int n, a; scanf("%d", &n); inverse(n); }
#include1113: 递归调用的次数统计(函数专题) Cvoid convert(int n) { if(n > 0) { convert(n/2); printf("%d", n % 2); } } int main() { int n; scanf("%d", &n); convert(n); }
#include1114: 逆序(数组) Cint fib(int k); int i=0; int main(void) { int n; scanf("%d", &n); printf("%dn", fib(n)); printf("递归调用了%d次", i); return 0; } int fib(int k) { i++; if (k == 1 || k == 2) return 1; else return fib(k - 1) + fib(k - 2); }
#include1115: 数组最小值(数组) C#define N 10 int main() { int n,i; scanf("%d", &n); int a[N]; for (i = 0; i < n; i++) scanf("%d", &a[i]); for (i = n - 1; i >= 0; i--) printf("%4d", a[i]); }
#include1116: 删除元素(数组) C#define N 1000 int main() { int a[N],n,max,t=0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); if(i==0) max = a[i]; if (max > a[i]) { max = a[i]; t = i; } } printf("%d %d", max, t); }
#include1117: 查找数组元素(数组) Cvoid PrintArr(int b[],int n) { for(int i=0;i<=n;i++) { printf("%d ",b[i]); } } void del(int a[], int n, int i) { int t=0; while(t!=i) t++; for(;t<=n;t++) { a[t]=a[t+1]; } PrintArr (a,n-2); } int main() { int a[10],n,i; scanf("%dn",&n); for(i=0;i<=n-1;i++) scanf("%d",&a[i]); scanf("%d",&i); del(a,n,i); }
#include1118: 有序数组的元素添加 Cint m = 0; void PrintArr(int a[], int n) { for (int i = 0; i < n; i++) { printf("%4d",a[i]); } } void del(int a[], int n, int i) { int t = 0; while (t != i) t++; for (; t <= n; t++) { a[t] = a[t + 1]; } PrintArr(a, n - 1); } int find(int a[], int n, int x) { for (int i = 0; i < n; i++) { if (a[i] == x) return i; else m++; } if (m == n) return -1; } int main() { int n, a[10], x; scanf("%d",&n); for (int i = 0; i < n; i++) scanf("%d",&a[i]); scanf("%d",&x); m = find(a, n, x); if (m == -1) printf("Not Found"); else del(a, n, m); }
#include1119: 一维数组排序(数组) Cvoid insert(int a[], int n, int num); void PrintArr(int a[], int n); int main() { int a[100], n, num; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } scanf("%d", &num); insert(a, n, num); } void insert(int a[], int n, int num) { int i; for ( i = n-1; a[i] > num; i--) { a[i+1] = a[i]; } a[i+1] = num; PrintArr(a, n); } void PrintArr(int a[], int n) { for (int i = 0; i <= n; i++) printf("%d ", a[i]); }
#includevoid sort(int a[], int n); void PrintArr(int a[], int n); int main() { int a[10],n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } sort(a, n); } void sort(int a[], int n) { int m; for(int i=0;i 1120: 最值交换 C #include1121: 电梯 Cint MinIndex(int a[], int n); int MaxIndex(int a[], int n); void PrintArr(int a[], int n); int main() { int m,n, a[10],min,max; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } min = MinIndex(a, n); m = a[min]; a[min] = a[0]; a[0] = m; max = MaxIndex(a, n); m = a[max]; a[max] = a[n-1]; a[n-1] = m; PrintArr(a, n); } void PrintArr(int a[], int n) { for (int i = 0; i < n; i++) printf("%d ", a[i]); } int MinIndex(int a[], int n) { int min,t=0; min = a[0]; for (int i = 0; i < n; i++) { if (min > a[i]) { min = a[i]; t = i; } } return t; } int MaxIndex(int a[], int n) { int max, t = 0; max = a[0]; for (int i = 0; i < n; i++) { if (max < a[i]) { max = a[i]; t = i; } } return t; } #include1122: 小明的调查作业 Cint main() { int a[1000], n, t = 0; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); for (int i = 0; i < n; i++) { if (i == 0) t += (a[0]) * 6 + 5; else if (a[i] > a[i - 1]) t += (a[i] - a[i - 1]) * 6 + 5; else if (a[i] < a[i - 1]) t += (a[i - 1] - a[i]) * 4 + 5; else if (a[i] == a[i - 1]) t += 5; } printf("%d", t); } #includeint xiangtonggeshu(int a[],int n); void paixv(int a[], int n, int t); void shanchu(int a[], int n); int main() { int a[1000],n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); shanchu(a, n); } int xiangtonggeshu(int a[], int n) { int t=0; for (int i = 0; i < n; i++) if (a[i]>=0) t += 1; return t; } void shanchu(int a[], int n) { int m; for (int i = 0; i < n; i++) { for (int j = i+1; j < n; j++) { if (a[i] == a[j]&&a[i]>=0) { for (int k = j; k < n; k++) { a[k] = a[k + 1]; } j -= 1; n -= 1; } } } int t; t = xiangtonggeshu(a, n); printf("%dn", t); paixv(a, n, t); } void paixv(int a[], int n, int t) { int m; for(int i=0;i 1123: 成绩排序 C(code1) #includeC(code2)#include void paixv(); int a[20], n; char b[20][2000]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%s", b[i]); scanf("%d", &a[i]); } paixv(); } void paixv() { int m; char temp[20]; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { m = strcmp(b[i], b[j]); if (a[i] > a[j]) { m = a[j]; a[j] = a[i]; a[i] = m; strcpy(temp, b[j]); strcpy(b[j], b[i]); strcpy(b[i], temp); j--; } else if (a[i] == a[j]&&m < 0) { m = a[j]; a[j] = a[i]; a[i] = m; strcpy(temp, b[j]); strcpy(b[j], b[i]); strcpy(b[i], temp); j--; } } for (int i = 0; i < n; i++) { { printf("%s ", b[i]); } printf("%dn", a[i]); } } #include1124: 两个有序数组合并 C#include int main() { int n, fraction[21], i, j, mid; char name[21][21], mid1[21]; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%s%d", name[i], &fraction[i]); for (i = 0; i < n - 1; i++) { for (j = i + 1; j < n; j++) { if (fraction[i] < fraction[j]) { mid = fraction[i]; fraction[i] = fraction[j]; fraction[j] = mid; strcpy(mid1, name[i]); strcpy(name[i], name[j]); strcpy(name[j], mid1); } if (fraction[i] == fraction[j]) if (strcmp(name[i], name[j]) > 0) { mid = fraction[i]; fraction[i] = fraction[j]; fraction[j] = mid; strcpy(mid1, name[i]); strcpy(name[i], name[j]); strcpy(name[j], mid1); } } } for (i = 0; i < n; i++) printf("%s %dn", name[i], fraction[i]); return 0; } #include1125: 上三角矩阵的判断 Cint m, n, a[1000001], b[1000001], i, c[2000003], p=0, q=0; int main() { scanf("%d", &m); for (i = m-1; i >= 0; i--) { scanf("%d", &a[i]); } scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &b[i]); } for (i = 0; i < m + n;i++) { if (a[p] > b[q]) { c[i] = a[p]; p++; } else { c[i] = b[q]; q++; } } for (i = 0; i < m + n; i++) { printf("%d ", c[i]); } } #includeint IsUpperTriMatrix(int a[][11], int n); int main() { int m, a[11][11]; scanf("%d", &m); for(int i=0;i 1126: 布尔矩阵的奇偶性 C #includeint BalanceMatrix(int a[][111], int n); int X, Y; int main() { int m, a[111][111]; scanf("%d", &m); for(int i=0;i 1127: 矩阵乘积 C #include1128: 课程平均分 Cint main() { int m, p, n, a[11][11], b[11][11], c[11][11],t=0,x=0,y=0; scanf("%d %d %d", &m, &p, &n); for (int i = 0, j; i < m; i++) for (j = 0; j < p; j++) scanf("%d", &a[i][j]); for (int i = 0, j; i < p; i++) for (j = 0; j < n; j++) scanf("%d", &b[i][j]); for (int i = 0, j,k; i < m; i++) { for (k = 0; k < n; k++) { for (j = 0; j < p; j++) { t += a[i][j] * b[j][k]; } c[x][y] = t; y++; if (y == n) { x++; y = 0; } t = 0; } } for (int i = 0, j; i < m; i++) { for (j = 0; j < n; j++) { printf("%d ", c[i][j]); } printf("n"); } } #include1129: 第几天 Cint main() { int m, n; double ans=0,a[1002][20]; scanf("%d%d", &m, &n); for (int i = 0, j; i < m; i++) for (j = 0; j < n; j++) scanf("%lf", &a[i][j]); for (int j = 0, i; j < n; j++) { ans = 0; for (i = 0; i < m; i++) { ans += a[i][j]; } printf("%.2f ", ans / m); } } #includeint a[2][13]={{0,31,29,31,30,31,30,31,31,30,31,30,31},{0,31,28,31,30,31,30,31,31,30,31,30,31}}; int main() { int year,month,day,ans=0,pd; scanf("%d-%d-%d",&year,&month,&day); if(year%4==0&&year%100!=0||year%400==0) pd=0; else pd=1; for(int i=1;i 1130: 杨辉三角 C #include1131: 最常用字符 Cint main() { int n,a[31][31]={0}; scanf("%d",&n); a[0][0]=1; for(int i=1;i<=n;i++) { for(int j=1;j<=i;j++) { a[i][j]=a[i-1][j]+a[i-1][j-1]; printf("%d ",a[i][j]); } printf("n"); } } #includeint a[26]={0},t,m; char b[105]={0}; int main() { gets(b); for(int i=0;b[i]!='';i++) { if((int)b[i]==32) { continue; } if(b[i]>='a'&&b[i]<='z') a[b[i]-'a'+1]++; else a[b[i]-'A'+1]++; } t=a[1]; m=1; for(int i=1;i<=26;i++) if(t 1132: 数字字符统计(多实例) C #include1133: 单词个数统计 Cint main() { char a[1005]; int n, t; scanf("%dn", &n); for (int x = 1; x <= n; x++) { gets(a); t = 0; for (int i = 0; a[i] != ''; i++) if (a[i] >= '0' && a[i] <= '9') t++; printf("%dn", t); } } #include#include int main() { char str[1000]; int i,len,count; gets(str); count=0; for(i=0;str[i]!='';i++) { if(str[i]!=' '&&str[i+1]==' ') count++; } len=strlen(str); if(str[len-1]!=' ') count++; printf("%dn",count); return 0; }
待更
C欢迎分享,转载请注明来源:内存溢出
评论列表(0条)