新生44

 Not Found

You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print None instead.

Constraints
1≤|S|≤105 (|S| is the length of string S.)
S consists of lowercase English letters.

输入

Input is given from Standard Input in the following format:
S
 

输出

Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print None instead.
 

样例输入 Copy

atcoderregularcontest

样例输出 Copy

b

提示

The string atcoderregularcontest contains a, but does not contain b.
mp一一对应就行
复制代码
#include<iostream>
#include<map>
using namespace std;
map<char,bool> mp;
int main(){
    string ch;
    cin>>ch;
    for(int i=0;i<ch.size();i++)
    {
        char c;
        c=ch[i];
        mp[c]=true;
    }
    int x=1;
    for(char i='a';i<='z';i++)
    {
        if(mp[i]==false)
        {
            x=0;
            cout<<i<<endl;
            break;
        }
    }
    if(x)
        cout<<"None"<<endl;
    return 0;
}
复制代码

 

 Make a Rectangle:

题目描述

We have N sticks with negligible thickness. The length of the i-th stick is Ai.
Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.

Constraints
4≤N≤105
1≤Ai≤109
Ai is an integer.

输入

Input is given from Standard Input in the following format:
N
A1 A2 ... AN
 

输出

Print the maximum possible area of the rectangle. If no rectangle can be formed, print 0.

样例输入 Copy

6
3 1 2 4 2 1

样例输出 Copy

2

提示

1×2 rectangle can be formed.
这个原来我用桶排记录次数,然后稍微优化了一下,结果还是内存超限
又想到离散化啥的乱七八糟的
最后一看好像直接模拟就行...
复制代码
#include<iostream>
#include<algorithm>
using namespace std;
const int N=1e5+10;
long long int a[N];
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n,greater<int>());
    long long int t=0,x=0,y=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]==a[i+1])
        {
            t++;
            i++;//相当于加两次 
            if(t==1)
                x=a[i];
            if(t==2)
            {
                y=a[i];
                break;
            }        
        }
    }
    //cout<<x<<" "<<y<<endl;
    if(t==2)
        cout<<x*y<<endl;
    else
        cout<<"0"<<endl;
    return 0;
}
复制代码

 

表达式求值

题目描述

给定一个只包含加法和乘法的算术表达式,请你编程计算表达式的值。

输入

输入仅有一行,为需要你计算的表达式,表达式中只包含数字、加法运算符“+”和乘法运算符“*”,且没有括号,所有参与运算的数字均为 0 到 2^31-1 之间的整数。输入数据保证这一行只有 0~ 9、+、*这 12 种字符。

输出

输出只有一行,包含一个整数, 表示这个表达式的值。 注意: 当答案长度多于 4 位时,请只输出最后 4 位,前导 0 不输出。

样例输入 Copy

【样例1】
1+1*3+4
【样例2】
1+1234567890*1
【样例3】
1+1000000003*1

样例输出 Copy

【样例1】
8
【样例2】
7891
【样例3】
4

提示

30%的数据,0≤加法运算符和乘法运算符的总数≤100;
80%的数据,0≤加法运算符和乘法运算符的总数≤1000;
100%的数据,0≤加法运算符和乘法运算符的总数≤100000。
原来以为会是高精来着,后来一看答案输出后四位,这不就是模运算吗,hhhh
复制代码
#include<iostream>
#include<stack>
#include<string>
#include<cstring>
#include<algorithm>
#include<unordered_map> 
using namespace std;
const int N=100010;
stack<long long int> num;
stack<char> ch;
void eval(){
    auto b=num.top();num.pop();
    auto a=num.top();num.pop();
    auto c=ch.top();ch.pop();
    int x;
    if(c=='+') x=a+b;
    else if(c=='*') x=a*b;
    num.push(x%10000);
}
int main(){
    unordered_map<char,int> pr{{'+',1},{'*',2}};
    string str;
    cin>>str;
    for(int i=0;i<str.size();i++)
    {
        auto c=str[i];
        if(isdigit(c))
        {
            long long int x=0,j=i;
            while(j<str.size()&&isdigit(str[j]))
                x=x*10+str[j++]-'0';
            i=j-1;
            num.push(x%10000);
        }
        else 
        {
            while(ch.size()&&pr[ch.top()]>=pr[c]) eval();
            ch.push(c);//判断优先级之后要入栈 
        }
    } 
    while(ch.size()) eval();
    cout<<num.top()%10000<<endl;
    return 0;
}
复制代码

 

posted @   小志61314  阅读(26)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示