ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

新生44

2022-02-16 13:33:48  阅读:192  来源: 互联网

标签:ch int 44 样例 新生 运算符 num include


 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;
}

 

标签:ch,int,44,样例,新生,运算符,num,include
来源: https://www.cnblogs.com/ccwz7/p/15899283.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有