第1周编程练习
1.逆序的三位数
- #include<stdio.h>
- int main()
- {
- int a, b, c, d;
- scanf(“%d”, &a);
- b = a/100;
- c = a%100/10;
- d = a%10;
- a = b+c*10+d*100;
- printf(“%d”, a);
- return 0;
- }
第2周编程练习
1.时间换算
- #include<stdio.h>
- int main()
- {
- int t, h, m;
- scanf(“%d”, &t);
- h = t/100;
- m = t%100;
- if(h>=8){
- h = h-8;
- }
- else{
- h = h+16;
- }
- t = h*100+m;
- printf(“%d”, t);
- return 0;
- }
2.信号报告
- #include<stdio.h>
- int main()
- {
- int R, S, N;
- scanf(“%d”, &N);
- R = N/10;
- S = N%10;
- switch(S){
- case 1:
- printf(“Faint signals, barely perceptible,”);
- break;
- case 2:
- printf(“Very weak signals,”);
- break;
- case 3:
- printf(“Weak signals,”);
- break;
- case 4:
- printf(“Fair signals,”);
- break;
- case 5:
- printf(“Fairly good signals,”);
- break;
- case 6:
- printf(“Good signals,”);
- break;
- case 7:
- printf(“Moderately strong signals,”);
- break;
- case 8:
- printf(“Strong signals,”);
- break;
- case 9:
- printf(“Extremely strong signals,”);
- break;
- }
- switch(R){
- case 1:
- printf(” unreadable.”);
- break;
- case 2:
- printf(” barely readable, occasional words distinguishable.”);
- break;
- case 3:
- printf(” readable with considerable difficulty.”);
- break;
- case 4:
- printf(” readable with practically no difficulty.”);
- break;
- case 5:
- printf(” perfectly readable.”);
- break;
- }
- return 0;
- }
第3周编程练习
1.奇偶个数
- #include<stdio.h>
- int main()
- {
- int a, b = 0, c = 0;
- scanf (“%d”, &a);
- while(a!=-1){
- if(a%2 == 0){
- b++;
- scanf (“%d”, &a);
- }
- else{
- c++;
- scanf (“%d”, &a);
- }
- }
- printf(“%d %d”, c, b);
- return 0;
- }
2.数字特征值
- #include<stdio.h>
- #include<math.h>
- int main()
- {
- int n, c, a = 0, d = 0;
- scanf (“%d”, &n);
- do{
- c = n%10;
- a++;
- if((c+a)%2==0){
- d += pow(2,a-1);
- }
- n/=10;
- }while(n>0);
- printf(“%d”, d);
- return 0;
- }
第4周编程练习
1.素数和
- #include<stdio.h>
- #include<math.h>
- int prime(int a)
- {
- int i;
- if((a==1)||(a!=2)&&(a%2==0)) return 0;
- for(i=3;i<=sqrt(a);i=i+2)
- {
- if(a%i==0) return 0;
- }
- return 1;
- }
- int main(void)
- {
- int count=1,i=2,m,n,sum=0;
- scanf(“%d %d”,&m,&n);
- while(count<m){
- if(prime(i)){
- //printf(“i1 = %d\n”,i);
- count++;
- i++;
- }
- else i++;
- }
- while(count<=n)
- {
- if(prime(i)){
- //printf(“i2 = %d\n”,i);
- sum+=i;
- //printf(“sum = %d\n”,sum);
- i++;
- count++;
- }
- else i++;
- }
- printf(“%d”,sum);
- }
2.念整数
- #include<stdio.h>
- #include<math.h>
- int main()
- {
- int x,count=0,i;
- scanf(“%d”,&x);
- if(x<0){
- printf(“fu “);
- x=-x;
- }
- i = x;
- do{
- count++;
- i/=10;
- }while(i>0);
- //printf(“%d”,count);
- while(count>0){
- i=x/pow(10,count-1);
- //count–;
- switch(i%10){
- case 0:
- if(count==1) printf(“ling”);
- else printf(“ling “);
- break;
- case 1:
- if(count==1) printf(“yi”);
- else printf(“yi “);
- break;
- case 2:
- if(count==1) printf(“er”);
- else printf(“er “);
- break;
- case 3:
- if(count==1) printf(“san”);
- else printf(“san “);
- break;
- case 4:
- if(count==1) printf(“si”);
- else printf(“si “);
- break;
- case 5:
- if(count==1) printf(“wu”);
- else printf(“wu “);
- break;
- case 6:
- if(count==1) printf(“liu”);
- else printf(“liu “);
- break;
- case 7:
- if(count==1) printf(“qi”);
- else printf(“qi “);
- break;
- case 8:
- if(count==1) printf(“ba”);
- else printf(“ba “);
- break;
- case 9:
- if(count==1) printf(“jiu”);
- else printf(“jiu “);
- break;
- }
- count–;
- }
- }
第5周编程练习
1.高精度小数
- #include<stdio.h>
- int main()
- {
- int a,b,i,mo,x;
- scanf(“%d/%d”,&a,&b);
- if(a==0){
- printf(“0”);
- return 0;
- }
- printf(“0.”);
- x=a;
- mo = x%b;
- for(i=1;i<=200&&mo!=0;++i){
- x*=10;
- mo = x%b;
- printf(“%d”,x/b);
- x=mo;
- }
- printf(“\n”);
- }
第6周编程练习
1.分解质因数
- #include<stdio.h>
- #include<math.h>
- int prime(int a);
- int main()
- {
- int a,i;
- scanf(“%d”,&a);
- if(prime(a)){
- printf(“%d=%d”,a,a);
- return 0;
- }
- for(i=2;i<a;i++){
- if(prime(i)&&a%i==0){
- printf(“%d=%d”,a,i);
- a=a/i;
- break;
- }
- }
- while(a>=i){
- if(prime(i)){
- if(a%i==0) {
- printf(“x%d”,i);
- a=a/i;
- }
- else i++;
- }
- else i++;
- }
- }
- int prime(int a)
- {
- int i;
- if((a==1)||((a!=2)&&(a%2==0))) return 0;
- for(i=3;i<=sqrt(a);i=i+2)
- {
- if(a%i==0) return 0;
- }
- return 1;
- }
2.完数
- #include<stdio.h>
- int perfect(int a);
- int main()
- {
- int m,n,i,flag1=1,flag2=1;
- scanf(“%d %d”,&m,&n);
- if(m==1) m++;
- for(i=m;i<=n;++i){
- if(perfect(i)&&flag1==1){
- flag1=0;
- flag2=0;
- printf(“%d”,i);
- }
- else if(perfect(i)&&flag1==0){
- printf(” %d”,i);
- }
- }
- if(flag2) printf(“NIL\n”);
- }
- int perfect(int a)
- {
- int i,sum;
- sum=1;
- for(i=2;i<a;i++)
- {
- if(a%i==0){
- sum+=i;
- }
- }
- if(sum==a) return 1;
- else return 0;
- }
第7周编程练习
1.多项式加法
- #include <stdio.h>
- int main()
- {
- int power,coefficient,flag=1,m_power=0,i;
- static int number[101];
- for(i=0;i<2;i++){
- do{
- scanf(“%d %d”,&power,&coefficient);
- number[power]+=coefficient;
- if(m_power<power) m_power=power;
- }while(power!=0);
- }
- for(i=m_power;i>1;i–)
- {
- if(flag==0){
- if(number[i]==1) printf(“+x%d”,i);
- else if(number[i]==-1) printf(“-x%d”,i);
- else if(number[i]>0) printf(“+%dx%d”,number[i],i);
- else if(number[i]<0) printf(“%dx%d”,number[i],i);
- }
- else{
- switch (number[i]){
- case 0:
- break;
- case 1:
- printf(“x%d”,i);
- flag=0;
- break;
- case -1:
- printf(“-x%d”,i);
- flag=0;
- break;
- default:
- printf(“%dx%d”,number[i],i);
- flag=0;
- break;
- }
- }
- }
- if(flag==0){
- if(number[1]==1) printf(“+x”);
- else if(number[1]==-1) printf(“-x”);
- else if(number[1]>0) printf(“+%dx”,number[1]);
- else if(number[1]<0) printf(“%dx”,number[1]);
- if(number[0]>0) printf(“+%d”,number[0]);
- else if(number[0]<0) printf(“%d”,number[0]);
- }
- else{
- switch (number[1]){
- case 0:
- break;
- case 1:
- printf(“x”);
- flag=0;
- break;
- case -1:
- printf(“-x”);
- flag=0;
- break;
- default:
- printf(“%dx”,number[1]);
- flag=0;
- break;
- }
- if(number[0]!=0){
- printf(“%d”,number[0]);
- flag=0;
- }
- }
- if(flag) printf(“0”);
- printf(“\n”);
- }
2.鞍点
- #include<stdio.h>
- int main()
- {
- int n,i,j,x,y,k;
- scanf(“%d”,&n);
- int jz[n][n];
- for(i=0;i<n;i++){
- for(j=0;j<n;j++){
- scanf(“%d”,&jz[i][j]);
- }
- }
- for(i=0;i<n;i++){
- for(j=0;j<n;j++){
- x=0;
- y=0;
- for(k=0;k<n;k++){
- if(jz[i][j]>jz[k][j]) x++;
- }
- if(x) continue;
- for(k=0;k<n;k++){
- if(jz[i][j]<jz[i][k]) y++;
- }
- if(y) continue;
- else{
- printf(“%d %d”,i,j);
- return 0;
- }
- }
- }
- printf(“NO”);
- }
第8周编程练习
1.单词长度
- /*#include<stdio.h>
- int main()
- {
- int count = 0,flag=0;
- char c;
- while((c=getchar())!=’.’){
- if(c==’ ‘&&count>0&&flag == 0){
- printf(“%d”,count);
- count = 0;
- flag = 1;
- }
- else if(c==’ ‘&&count>0&&flag == 1){
- printf(” %d”,count);
- count = 0;
- }
- else if(c!=’ ‘){
- count++;
- }
- }
- if(count>0) printf(” %d”,count);
- }*/
- //上面那个当输出一个单词,例如kkkkk.的时候会有格式错误,反正上面这么写就是很麻烦!!!
- #include <stdio.h>
- int main()
- {
- static int count;
- char ch;
- while(scanf(“%c”,&ch)!=EOF){
- if(ch == ‘.’){
- if(count!=0) printf(“%d”,count);
- break;
- }
- if(ch==’ ‘){
- if(count!=0){
- printf(“%d “,count);
- count=0;
- }
- }
- else count+=1;
- }
- }