|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
对于一个正整数 n , 大于 n 、个位数为 8 的数有很多个。
请你在大于 n 、个位数为 8 的所有数中,找出最小的哪一个数并输出。
输入
输入一个正整数 n (0 < n <= 10000 )
输出
输出大于n、个位数为 8的最小数。
样例输入 Copy
1688
样例输出 Copy
1698
#include <stdio.h>
#include <string.h>
char str[100001];
int main() {
int len;
int num=0;
while((scanf("%s",&str))!=EOF) {
len=strlen(str);
if(str[len-1]<'8') {
str[len-1]='8';
}
if(str[len-1]>='8') {
str[len-1]='8';
for(int i=1; i<len; i++) {
if(str[len-1-i]<='8') {
str[len-1-i]++;
break;
}
}
}
puts(str);
// for(int i=0; i<len; i++)
// num=num*10+str[i]-'0';
// printf("%d",num);
}
}
本帖最后由 jhq999 于 2021-12-6 21:48 编辑
- if(n%10<8)
- {
- n=n-(n%10)+8;
- }
- else
- n=(n/10+1)*10+8;
复制代码
|
|