#include <stdio.h> #include <stdbool.h> #include <string.h>

int check(int n) { // 判断有几个不同的数字 bool vis[10] = {0}; while (n) { if (vis[n % 10]) return 0; vis[n % 10] = true; n /= 10; } return 1; }

int main() { int y, n = 0; scanf("%d %d", &y, &n); for (int x = 0; x <= 100; x++) { int year = y + x; char s[10]; sprintf(s, "%04d", year); int len = strlen(s), cnt = 0; for (int i = 0; i < len; i++) { for (int j = i + 1; j < len; j++) { if (s[i] == s[j]) { cnt = 0; goto end; } } } cnt = check(year); if (cnt == n) { printf("%d %s\n", x, s); break; } end:; } return 0;

编写一个C语言代码根据要求自动填充我出生于y年直到x岁才遇到n个数字都不相同的年份这句话。输入格式:输入在一行中给出出生年份y和目标年份中不同数字的个数n其中y在1 3000之间n可以是2、或3、或4。注意不足4位的年份要在前面补零例如公元1年被认为是0001年有2个不同的数字0和1。输出格式:根据输入输出x和能达到要求的年份。数字间以1个空格分隔行首尾不得有多余空格。年份要按4位输出。注意:所谓

原文地址: http://www.cveoy.top/t/topic/hmUs 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录