现在位置: 首页 > 例题 > 文章
2011年04月08日 例题 ⁄ 共 311字 暂无评论
判读素数和对称数 Description: 判断一个数是否为对称三位数素数。 所谓“对称”是指一个数,倒过来还是该数。例如,375不是对称数,因为倒过来变成了573。 Input: 输入数据含有不多于50个的正整数(0<n<2^32)。 Output: 对于每个n,如果该数是对称三位数素数,则输出“Yes”,否则输出“No”。每个判断结果单独列一行。 Sample Input: 11 101 272 Sample Output: No Yes No 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 2...
阅读全文
2011年03月31日 例题 ⁄ 共 163字 暂无评论
栈的典型例子 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 #include <iostream> #include <stack>   const int MAXN = 1000 + 10; int n, target[MAXN];   using namespace std;   int main(int argc, char *argv[]) { while (scanf("%d", &n) == 1) { stack<int> s;...
阅读全文
2011年03月31日 例题 ⁄ 共 834字 暂无评论
简单的计算就出错了 题目描述: 设圆半径r,圆柱高h 求圆周长C1、圆面积Sa、圆球表面积Sb、圆球体积Va、圆柱体积Vb。 用scanf输入数据,输出计算结果,输出时要求文字说明,取小数点后两位数字。请编程序。 PI=3.14 输入 两个浮点数,r和h 输出 C1=9.42 Sa=7.07 Sb=28.26 Va=14.13 Vb=21.19 提示:需要注意输出的字母的大小写 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #include <stdio.h> int main(int arg...
阅读全文
统计英文字母、空格、数字和其他字符的个数 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 #include <stdio.h>   int main(int argc, char *argv[]) { int c; int nchar=0; int nwhite=0; int ndigit=0; int nothers=0;   while((c=getchar())!='n') { if ((c>='a' &&c<='z') || (c>='A'...
阅读全文
2011年03月22日 例题 ⁄ 共 102字 暂无评论
基本练习 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 #include <stdio.h>   int main(int argc, char *argv[]) { int n; int i, j; int limit;   scanf("%d", &n);   limit = sqrt(n) + 1;   for (i=2; i<=limit; i++) while (n%i==0) { printf("%dn", i); n = n/i; ...
阅读全文
2011年03月20日 例题 ⁄ 共 197字 暂无评论
数组 首先实现打印功能 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 #include <stdio.h> #define MAX_SIZE 10   void print_big_number(int big[], int len) { int i;   i=len; while (big[--i]==0); do { printf("%d", big[i]); } while (i--); }   int mai...
阅读全文
2011年03月14日 例题 ⁄ 共 134字 暂无评论
任意给出一个四位数,把它重新组成一个四位的最大数和一个最小数,算出两者间的差。 例如:3721这个数,可以重组成:7321和1237,相数之差为7321-1237 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 void f(int n) { int N[4]; int i, j, t, n_min=0, n_max=0;   for(i=0; i<4; i++) { N[3-i] = n % 10;...
阅读全文
2011年03月14日 例题 ⁄ 共 160字 暂无评论
将任意整数进行因式分解,如:12=2*2*3,输出格式见示例 样例输入 60 样例输出 2 2 3 5 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 void f(int n) { int i; for(i=2; i<n/2; i++) { while (n%i==0) { printf("%dn",i); n = n / i; } } if (n>1) printf("%dn", n); }  ...
阅读全文
2011年03月08日 例题 ⁄ 共 93字 暂无评论
任意给出一个四位数,把它重新组成一个四位的最大数和一个最小数,算出两者间的差。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 #include <stdio.h>   int f(int n) { int N[4], t, n_min, n_max, i,j;   for(i=0; i<4; i++) { N[3-i] = n % 10; n = n / 10; } for(i=0...
阅读全文
2011年03月08日 例题 ⁄ 共 117字 暂无评论
将任意整数进行因式分解 12 = 2*2*3; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 #include <stdio.h>   void f(int n) { int i; for(i=2; i<n/2; i++) { while (n%i==0) { printf("%4d", i); n = n / i; } } if(n>1) printf("%4d", n); }   int main&...
阅读全文