Codeup 算法笔记 4.2-哈希 Problem C&Problem D:Be Unique & String Subtraction

Problem C

题目描述

Being unique is so important to people on Mars that even their lottery is designed in a unique way. The rule of winning is simple: one bets on a number chosen from [1, 104]. The first one who bets on a unique number wins. For example, if there are 7 people betting on 5 31 5 88 67 88 17, then the second one who bets on 31 wins

输入

Each input file contains one test case. Each case contains a line which begins with a positive integer N (<=10^5) and then followed by N bets. The numbers are separated by a space.

输出

For each test case, print the winning number in a line. If there is no winner, print "None" instead.

样例输入

7 5 31 5 88 67 88 17
5 888 666 666 888 888

样例输出

31
None

思路:题意是找第一个唯一出现的数。方法:暴力解。

AC代码

#include<cstdio>
#include<cstring>
int hash[100010];
int value[100010];
int main() {
    int num;
    while(scanf("%d",&num)!=EOF){
        memset(hash,-1,sizeof(int)*100010);
        for(int i=0;i<num;i++){
            scanf("%d",&value[i]);
            hash[value[i]]++;
        }
        int flag=0;
        for(int i=0;i<num;i++){
            if(hash[value[i]]==0){
                flag=1;
                printf("%d\n",value[i]);
                break;
            }
        }
        if(flag==0){
            printf("None\n");
        }
    }
    return 0;
}


Problem D

题目描述

Given two strings S1 and S2, S = S1 - S2 is defined to be the remaining string after taking all the characters in S2 from S1. Your task is simply to calculate S1 - S2for any given strings. However, it might not be that simple to do it fast

输入

Each input file contains one test case. Each case consists of two lines which gives S1 and S2, respectively. The string lengths of both strings are no more than 104. It is guaranteed that all the characters are visible ASCII codes and white space, and a new line character signals the end of a string.

输出

For each test case, print S1 - S2 in one line.

输入样例

They are students.
aeiou

输出样例

Thy r stdnts.

思路:将出现过的s2hash处理,遍历s1。

AC代码

#include <cstdio>
#include <cstring>

char s1[10002];
char s2[10002];
int hash[1000];

int main() {
    while(gets(s1)!=NULL){
        gets(s2);
        memset(hash,0,sizeof(int)*1000);
        for(int i=0;i<strlen(s2);i++){
            hash[(int)(s2[i]-' ')]++;
        }
        
        for(int i=0;i<strlen(s1);i++){
            if(hash[(int)(s1[i]-' ')]!=0){
                continue;
            }
            printf("%c",s1[i]);
        }
        printf("\n");
    }
}

遇到的问题:

1、ascii码约在0~127,空格为32,空格开始输出可见(32~126),127为DEL;

2、gets()与scanf()不同,循环判断时应使用 gets(xx...)!=NULL 的形式。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
本项目是一个基于SpringBoot开发的华府便利店信息管理系统,使用了Vue和MySQL作为前端框架和数据库。该系统主要针对计算机相关专业的正在做毕设的学生和需要项目实战练习的Java学习者,包含项目源码、数据库脚本、项目说明等,有论文参考,可以直接作为毕设使用。 后台框架采用SpringBoot,数据库使用MySQL,开发环境为JDK、IDEA、Tomcat。项目经过严格调试,确保可以运行。如果基础还行,可以在代码基础之上进行改动以实现更多功能。 该系统的功能主要包括商品管理、订单管理、用户管理等模块。在商品管理模块中,可以添加、修改、删除商品信息;在订单管理模块中,可以查看订单详情、处理订单状态;在用户管理模块中,可以注册、登录、修改个人信息等。此外,系统还提供了数据统计功能,可以对销售数据进行统计和分析。 技术实现方面,前端采用Vue框架进行开发,后端使用SpringBoot框架搭建服务端应用。数据库采用MySQL进行数据存储和管理。整个系统通过前后端分离的方式实现,提高了系统的可维护性和可扩展性。同时,系统还采用了一些流行的技术和工具,如MyBatis、JPA等进行数据访问和操作,以及Maven进行项目管理和构建。 总之,本系统是一个基于SpringBoot开发的华府便利店信息管理系统,使用了Vue和MySQL作为前端框架和数据库。系统经过严格调试,确保可以运行。如果基础还行,可以在代码基础之上进行改动以实现更多功能。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值