AtCoder Beginner Contest 248 打比赛总结

4月16日(周六)又打了一场ABC。

结果:A,B题 AC(300分),C、D题 TLE

目录

网址

视频讲解

A题

题目描述

题目分析

题目代码

知识讲解

B题

题目描述

题目分析

题目代码

题目备注

C题

题目描述

题目分析

题目代码

其它

我的Atcoder账号

版权声明

投票收集


网址

UNIQUE VISION Programming Contest 2022(AtCoder Beginner Contest 248) - AtCoderAtCoder is a programming contest site for anyone from beginners to experts. We hold weekly programming contests online.https://atcoder.jp/contests/abc248

视频讲解

ABC 248 A~D 讲解

A题

题目描述

A - Lacked Number  / 
Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 100 points

Problem Statement
You are given a string S of length exactly 9 consisting of digits. One but all digits from 0 to 9 appear exactly once in S.

Print the only digit missing in S.

Constraints
S is a string of length 9 consisting of digits.
All characters in S are distinct.
Input
Input is given from Standard Input in the following format:

S
Output
Print the only digit missing in S.

Sample Input 1 
Copy
023456789
Sample Output 1 
Copy
1
The string 023456789 only lacks 1. Thus, 1 should be printed.

Sample Input 2 
Copy
459230781
Sample Output 2 
Copy
6
The string 459230781 only lacks 6. Thus, 6 should be printed.

Note that the digits in the string may not appear in increasing order.

题目分析

题目大意:

输入一个字符串,包含0~9中的9个数字,输出缺失的数。

思路:

先排序,再把字符串从头到尾循环。当i≠s[i],输出i,return 0。如果全部循环过一遍还没return 0,直接输出9(博主刚开始没cout<<9,WA了2次)。

题目代码

初次提交的WA代码:

#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
	cin>>s;
	sort(s.begin(),s.end());
	for(int i=0;i<s.size();i++) if(s[i]!=i+'0') {
		cout<<i;
		return 0;
	} 
    return 0;
}
//ACplease!!!


/*  printf("                                                                \n");
	printf("                                                                \n");
	printf("       * * *               * * *             * * *             * * *            \n");
	printf("     *       *           *       *         *      *          *       *         \n");
	pri
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值