7-36 小明的银行卡密码 (100 分)
小明想给自己的银行卡设置一个6位数字的密码,应符合如下规则:
(1)左侧数第1,3,5位数字为奇数;
(2)左侧数第2,4,6位数字为偶数;
(3)任意两位数字不相同;
(4)中间两位不是月份(不在1-12之间),后两位不是日期(不在1-31之间);
(5)前三位非升序非降序排列,后三位非升序非降序排列;
(6) 前三位与后三位之差被23整除余13。
请编程输入两个六位整数a,b, 输出区间[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 统计字符 (100 分)
从键盘输入一串字符(直到字符’.’为止),统计其中数字字符的个数。
输入格式:
请在这里写输入格式。例如:输入在一行中给出2个绝对值不超过1000的整数A和B。
输出格式:
请在这里描述输出格式。例如:对每一组输入,在一行中输出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 同构数 (100 分)
正整数n若是它平方数的尾部,则称n为同构数。例如:6是其平方数36的尾部,76是其平方数5776的尾部, 625是其平方数390625的尾部,6与76与625都是同构数。编程输入正整数N(10000>N>10),输出不小于N的第一个同构数。
输入样例:
18 -299
输出样例:
在这里给出相应的输出。例如:
-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 对一个字符串内整数数值求和 (10 分)
输入一个字符串,求出字符串内包含的整数数值的和。
输入格式:
输入在一行内不超过80个字符的字符串。
输出格式:
对输入的字符串,输出包含的整数数值的和。
输入样例:
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 序数词的缩写 (10 分)
在英语里,序数词的缩写形式参见下表:
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 |
请找出规律,编写程序,解决此问题。
首先输入正整数 n,然后输入 n 个正整数 a1,a2,⋯,an,最后输出 n 个对应的序数词缩写,缩写词间空一格,行末没有多余的空格。
输入格式
n
a1,a2,⋯,an
输出格式
n 个序数词的缩写
输入样例
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;
}