4月16日(周六)又打了一场ABC。
结果:A,B题 AC(300分),C、D题 TLE。
目录
网址
视频讲解
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