百练 2656 Unhappy Jinjin

题目链接:http://bailian.openjudge.cn/practice/2656

# include <stdio.h>
int main()
{
	while(1)
	{
		int i, n;		
		int maxday, maxvalue = -1;
		scanf("%d", &n);		
		if (n == 0) 
			break;
		for (i = 1; i <= n; i++)
		{
			int a, b;		
			scanf("%d %d", &a, &b);
			if (a + b > maxvalue) 
			{
				maxvalue = a + b;			
				maxday = i;	
			}
		}	
		if (maxvalue <= 8)
			printf("0\n");
		else 
			printf("%d\n", maxday);
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 很高兴回答你的问题。请看下面的代码: #include <stdio.h> int main() { long long n; int count = ; scanf("%lld", &n); while (n > ) { if (n % 10 == 6) { count++; printf("6"); } n /= 10; } if (count == ) { printf("Unhappy"); } return ; } 希望能帮到你! ### 回答2: 可以先将正整数n转换成字符串,然后遍历字符串中的每个字符,判断是否为'6',如果是则计数,最后输出计数结果。如果计数结果大于等于1,则输出对应数量的'6',否则输出"Unhappy"。 以下是用Python编写的程序示例: ```python def count_six(n): num_str = str(n) # 将正整数n转换为字符串 count = 0 # 初始化计数器 # 遍历字符串中的每个字符 for ch in num_str: if ch == '6': count += 1 # 如果字符为'6',计数器加1 if count >= 1: return '6' * count # 输出对应数量的'6' else: return 'Unhappy' # 示例输入 n = 1689466 result = count_six(n) print(result) # 输出: 666 n = 421078951 result = count_six(n) print(result) # 输出: Unhappy ``` 以上程序中定义了一个`count_six`函数,接受一个正整数n作为参数,并根据题目要求进行计数和输出操作。示例输入中的两个例子分别演示了有6和没有6的情况。 ### 回答3: 可以通过将数字n转换为字符串,然后遍历字符串中的每个字符,判断是否为字符'6'来统计数字中出现的6的个数。 下面是一个示例的Python代码实现: ```python def count_six(n): str_n = str(n) count = 0 for digit in str_n: if digit == '6': count += 1 return count n = int(input("请输入一个正整数n:")) result = count_six(n) if result > 0: print('6' * result) else: print('Unhappy') ``` 该代码首先将输入的数字n转换为字符串,然后使用一个计数器count来记录数字中出现的6的个数。接下来,通过遍历字符串中的每个字符,判断是否为字符'6',如果是,则将计数器count加1。 最后,判断计数器count的值,如果大于0,则输出相应个数的字符'6';如果等于0,则输出'Unhappy'表示没有出现6。 注意,这个程序是通过将输入的数字转换为字符串来实现的,该方法可用于处理n的范围在10^18内的情况。如果n的范围更大,可能需要使用其他方法进行处理。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值