7-36至7-40
7-36 小明的銀行卡密碼 (100 分)
小明想給自己的銀行卡設(shè)置一個(gè)6位數(shù)字的密碼,應(yīng)符合如下規(guī)則: (1)左側(cè)數(shù)第1,3,5位數(shù)字為奇數(shù); (2)左側(cè)數(shù)第2,4,6位數(shù)字為偶數(shù); (3)任意兩位數(shù)字不相同; (4)中間兩位不是月份(不在1-12之間),后兩位不是日期(不在1-31之間); (5)前三位非升序非降序排列,后三位非升序非降序排列; (6) 前三位與后三位之差被23整除余13。 請(qǐng)編程輸入兩個(gè)六位整數(shù)a,b, 輸出區(qū)間[a,b]之間所有符合條件的密碼。輸入樣例:
100000 999999輸出樣例:
307294 385096 387052 523096 529470 549076 563274 581476 583294 587436 705692 725436 769250 781492 785496 785634 901658 903476 923450 927638 947658 #include <stdio.h> #include <math.h>void func(int n,int *an) {for(int i=5;i>=0;i--){an[i] = n%10;n/=10;} } int main(){int m,n;scanf("%d%d",&m,&n);int a[6];for(int i=m;i<=n;i++){func(i,a);if(a[0]%2==0||a[2]%2==0||a[4]%2==0) continue;if(a[1]%2==1||a[3]%2==1||a[5]%2==1) continue;if(a[0]==a[1]||a[0]==a[2]||a[0]==a[3]||a[0]==a[4]||a[0]==a[5]) continue;if(a[1]==a[2]||a[1]==a[3]||a[1]==a[4]||a[1]==a[5]) continue;if(a[2]==a[3]||a[2]==a[4]||a[2]==a[5]) continue;if(a[3]==a[4]||a[3]==a[5]||a[4]==a[5]) continue;if(a[2]*10+a[3]>=1&&a[2]*10+a[3]<=12) continue;if(a[4]*10+a[5]>=1&&a[4]*10+a[5]<=31) continue;if(a[0]<a[1]&&a[1]<a[2]) continue;if(a[0]>a[1]&&a[1]>a[2]) continue;if(a[3]<a[4]&&a[4]<a[5]) continue;if(a[3]>a[4]&&a[4]>a[5]) continue;if((-a[3]*100-a[4]*10-a[5]+a[0]*100+a[1]*10+a[2])%23==13) printf("%d\n",i);}return 0; }?
7-37 統(tǒng)計(jì)字符 (100 分)
從鍵盤輸入一串字符(直到字符’.’為止),統(tǒng)計(jì)其中數(shù)字字符的個(gè)數(shù)。
輸入格式:
請(qǐng)?jiān)谶@里寫輸入格式。例如:輸入在一行中給出2個(gè)絕對(duì)值不超過(guò)1000的整數(shù)A和B。
輸出格式:
請(qǐng)?jiān)谶@里描述輸出格式。例如:對(duì)每一組輸入,在一行中輸出A+B的值。
輸入樣例:
dsffdsf18-299dsfasd.輸出樣例:
5 #include <stdio.h> #include <math.h>int main(){char ch;scanf("%c",&ch);int sum=0;while(ch!='.'){if(ch>='1'&&ch<='9'||ch=='0') sum++;scanf("%c",&ch);}printf("%d",sum);return 0; }?
7-38 同構(gòu)數(shù) (100 分)
正整數(shù)n若是它平方數(shù)的尾部,則稱n為同構(gòu)數(shù)。例如:6是其平方數(shù)36的尾部,76是其平方數(shù)5776的尾部, 625是其平方數(shù)390625的尾部,6與76與625都是同構(gòu)數(shù)。編程輸入正整數(shù)N(10000>N>10),輸出不小于N的第一個(gè)同構(gòu)數(shù)。
輸入樣例:
18 -299輸出樣例:
在這里給出相應(yīng)的輸出。例如:
-281 #include <stdio.h> #include <math.h>int main(){int n;scanf("%d",&n);while(1){int t = 1;while(n>=t) t*=10;if(n*n%t==n) {printf("%d\n",n);break;}n++;}return 0; }?
7-39 對(duì)一個(gè)字符串內(nèi)整數(shù)數(shù)值求和 (10 分)
輸入一個(gè)字符串,求出字符串內(nèi)包含的整數(shù)數(shù)值的和。
輸入格式:
輸入在一行內(nèi)不超過(guò)80個(gè)字符的字符串。
輸出格式:
對(duì)輸入的字符串,輸出包含的整數(shù)數(shù)值的和。
輸入樣例:
a12,x;y1.2輸出樣例:
15 #include <stdio.h> #include <string.h>int main(){char str[80];scanf("%s",str);int len = strlen(str);int t = 0;for(int i=0;i<len;i++){if(str[i]<'0'||str[i]>'9') continue;else{int sum = 0;while(str[i]>='0'&&str[i]<='9'){sum = sum*10+str[i]-48;i++;if(i==len)break;}t+=sum;}}printf("%d",t);return 0; }?
7-40 序數(shù)詞的縮寫 (10 分)
在英語(yǔ)里,序數(shù)詞的縮寫形式參見(jiàn)下表:
| 1st | 2nd | 3rd | 4th | 5th | 6th | 7th | 8th | 9th | 10th |
| 11th | 12th | 13th | 14th | 15th | 16th | 17th | 18th | 19th | 20th |
| 21st | 22nd | 23rd | 24th | 25th | 26th | 27th | 28th | 29th | 30th |
| 31st | 32nd | 33rd | 34th | 35th | 36th | 37th | 38th | 39th | 40th |
| 41st | 42nd | 43rd | 44th | 45th | 46th | 47th | 48th | 49th | 50th |
| 51st | 52nd | 53rd | 54th | 55th | 56th | 57th | 58th | 59th | 60th |
| 61st | 62nd | 63rd | 64th | 65th | 66th | 67th | 68th | 69th | 70th |
| 71st | 72nd | 73rd | 74th | 75th | 76th | 77th | 78th | 79th | 80th |
| 81st | 82nd | 83rd | 84th | 85th | 86th | 87th | 88th | 89th | 90th |
| 91st | 92nd | 93rd | 94th | 95th | 96th | 97th | 98th | 99th | 100th |
請(qǐng)找出規(guī)律,編寫程序,解決此問(wèn)題。
首先輸入正整數(shù) n,然后輸入 n 個(gè)正整數(shù) a?1??,a?2??,?,a?n??,最后輸出 n 個(gè)對(duì)應(yīng)的序數(shù)詞縮寫,縮寫詞間空一格,行末沒(méi)有多余的空格。
輸入格式
n
a?1??,a?2??,?,a?n??
輸出格式
n 個(gè)序數(shù)詞的縮寫
輸入樣例
4 71 412 1043 53618輸出樣例
71st 412th 1043rd 53618th #include <stdio.h> #include <string.h>int main(){int n;scanf("%d",&n);int a[n];for(int i=0;i<n;i++){scanf("%d",&a[i]);}for(int i=0;i<n;i++){int temp = a[i]%100;if(temp/10==1) printf("%dth",a[i]);else if(temp%10==1)printf("%dst",a[i]);else if(temp%10==2)printf("%dnd",a[i]);else if(temp%10==3)printf("%drd",a[i]);else printf("%dth",a[i]);if(i!=n-1) printf(" ");}return 0; }?
總結(jié)
- 上一篇: Abusing UIViewContro
- 下一篇: Openstack实验笔记