高薪offer在哪里! level
获赞
540
粉丝
69
关注
12
看过 TA
706
天津大学
2023
Python
IP属地:天津
暂未填写个人简介
私信
关注
2022-09-18 09:58
已编辑
天津大学 Python
题目: 有一个数组,要是相邻的两个数加起来是10的倍数,那么可以删掉这两个数,后面的数会顶上来 求: 最多可以删除多少个数字 n = int(input()) lis = list(map(int,input().strip().split())) global m  #全局变量,统计迭代次数 m = 0 def fun(num, ind):  #消消乐,消除到不能消为止     global m     if (num[ind] + num[ind + 1]) % 10 == 0:         num.pop(ind)         num.pop...
牛客632296172号:public class MSKJ2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int count = sc.nextInt(); List<Integer> list = new ArrayList<>(); sc.nextLine(); for (int i = 0; i < count; i++) { list.add(sc.nextInt()); } boolean flag = true; while(flag){ for (int i = 0; i < list.size()-1; i++) { if ((list.get(i) + list.get(i+1)) % 10 == 0){ list.remove(i); list.remove(i); flag = true; break; }else{ flag =false; } } if (list.size() < 2){ flag = false; } } System.out.println(count-list.size()); } }
投递民生科技等公司9个岗位 >
0 点赞 评论 收藏
分享
2022-09-05 16:37
已编辑
天津大学 Python
投递字节跳动等公司9个岗位 >
0 点赞 评论 收藏
分享

创作者周榜

更多
关注他的用户也关注了:
牛客网
牛客企业服务