|
亲!马上注册或者登录会查看更多内容!
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
1092 To Buy or Not to Buy
这个比top那个1004简单多了——就是给两个串问第一个串是否包含了第二个串的全部字符,如果是,多余出来多少个(其实就是长度差),如果不是,少几个…… 直接算就行。
- #include <cstdio>
- #include <cstring>
- #include <string>
- #include <cctype>
- using namespace std;
- char s[1003];
- int have[62];
- inline int give(char c) {
- if (isdigit(c)) {
- return c - '0';
- }
- if (isupper(c)) {
- return c - 'A' + 10;
- }
- return c - 'a' + 36;
- }
- void run() {
- scanf("%s",s);
- for (int i = 0; s【i】; ++i) {
- --have[give(s【i】)];
- }
- int extra = 0, need = 0;
- for (int i = 0; i < 62; ++i) {
- if (have【i】 < 0) {
- need -= have【i】;
- }
- else {
- extra += have【i】;
- }
- }
- if (need) {
- printf("No %d\n", need);
- }
- else {
- printf("Yes %d\n", extra);
- }
- }
- int main() {
- scanf("%s",s);
- for (int i = 0; s【i】; ++i) {
- ++have[give(s【i】)];
- }
- run();
- return 0;
- }
-
-
复制代码
|
|