计蒜客 - 44690/44691 字符串模拟

前天晚上做的时候爆零了 就这俩题 爆零了。。。

44690 Gas Price Is Going Up/Down

题意:给你三个三位数 每个数可能缺失0~1位
且三个数都在200~500之间
问你三个数最小可取多少
思路:暴力即可 1e2的复杂度。。。
最小的数尽可能小就行
然后暴力枚举!自己想多了
还有计算三位数的时候要先(int)一下 不然会爆
自己一直找不到wa点 是 a3写成a2了 我晕

#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define inf 0x3f3f3f3f
#define sd(a) scanf("%d",&a)
#define sdd(a,b) scanf("%d%d",&a,&b)
#define cl(a,b) memset(a,b,sizeof(a))
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define sddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define dbg() printf("aaa\n")
using namespace std;
int main() {
	int T;
    sd(T);
    rep(cas,1,T){
        string s[3],ss[3];
        int a1,a2,a3;
        cin>>s[0]>>s[1]>>s[2];
        ss[0]=s[0],ss[1]=s[1],ss[2]=s[2];
        if(s[0][0]=='-'){
            s[0][0]='2';
        }else if(s[0][1]=='-'){
            s[0][1]='0';
        }else if(s[0][2]=='-'){
            s[0][2]='0';
        }
        //再a2!!!
        a1=(int)(s[0][0]-'0')*100+(int)(s[0][1]-'0')*10+(int)(s[0][2]-'0');
        if(s[1][0]=='-'||s[1][1]=='-'||s[1][2]=='-'){
            for(int i=0;i<=9;i++){
                if(s[1][0]=='-'){
                    a2=i*100+(int)(s[1][1]-'0')*10+(int)(s[1][2]-'0');
                }else if(s[1][1]=='-'){
                    a2=(int)(s[1][0]-'0')*100+i*10+(int)(s[1][2]-'0');
                }else if(s[1][2]=='-'){
                    a2=(int)(s[1][0]-'0')*100+(int)(s[1][1]-'0')*10+i;
                }
                if(a2>a1) break;
            }
        }else{
            a2=(int)(s[1][0]-'0')*100+(int)(s[1][1]-'0')*10+(int)(s[1][2]-'0');
        }
        if(s[2][0]=='-'||s[2][1]=='-'||s[2][2]=='-'){
            for(int i=0;i<=9;i++){
                if(s[2][0]=='-'){
                    a3=i*100+(int)(s[2][1]-'0')*10+(int)(s[2][2]-'0');
                }else if(s[2][1]=='-'){
                    a3=(int)(s[2][0]-'0')*100+i*10+(int)(s[2][2]-'0');
                }else if(s[2][2]=='-'){
                    a3=(int)(s[2][0]-'0')*100+(int)(s[2][1]-'0')*10+i;
                }
                if(a3>a2&&a3<=500) break;
            }
        }else{//服了!!!这里写成a2.....
            a3=(int)(s[2][0]-'0')*100+(int)(s[2][1]-'0')*10+(int)(s[2][2]-'0');
        }
        
        printf("Gas Station #%d:\n",cas);
        cout<<"   Input:  "<<ss[0]<<" "<<ss[1]<<" "<<ss[2]<<endl;
        cout<<"   Output: "<<a1<<" "<<a2<<" "<<a3<<endl;
        cout<<endl;
    }
	return 0;
}

题目如下:
The gas stations have billboards showing the gas prices (we’ll assume only three categories of gas: Regular, Plus, and Super). These billboards display the prices of gas, but the problem is that sometimes some digits are missing from the prices on the billboards!
The Problem:
Given prices for the three categories of gas with at most one digit missing from a given price, you are to determine the exact value of each price. We will assume that Regular is cheaper than Plus which is cheaper than Super. Also assume that Regular is at leas 2.00 and Super is at most 5.00.
The Input:
There will be multiple billboards (test cases) in the input. The first input line contains a positive integer n, indicating the number of billboards to be processed. The billboards will be on the following n input lines, each on a separate line. Each billboard contains three prices, the first showing Regular, the second representing Plus, and the last showing Super. The first price starts in column one, each price uses three columns (decimal points are not in the input), and there is exactly one space separating prices. The characters used in a price are only digits 0 through 9 and hyphen to indicate a missing digit (there is at most one hyphen per price). Since gas is at least $2.00, the digits 0 or 1 will not appear as the first character for a price in the input. Similarly, the maximum gas price (5.00) dictates possible valid values for the first character.
The Output:
At the beginning of each test case, output “Gas Station #g:”, where g is the test case number (starting from 1). For each gas station, print the input values and then the output values (each on a separate line and indented three columns). If there are multiple possible (valid) answers, use the lowest valid value for Regular. Then, with the lowest valid value for Regular, use the lowest valid value for Plus. Then, with the lowest valid value for Plus, use the lowest valid value for Super. Assume that input values will always result into at least one possible valid answer.
Leave a blank line after the output for each test case. Follow the format illustrated in Sample Output. Be sure to line up the output with spaces (not tabs) exactly as given in Sample Output.
(Sample Input/Output on the next page)
样例输入
2
2-9 285 -99
-50 -99 -99
样例输出
Gas Station #1:
Input: 2-9 285 -99
Output: 209 285 299

Gas Station #2:
Input: -50 -99 -99
Output: 250 299 399

44691 Broken Space Bar

题意:给你一个单词集合 问你n串字符串 问你该字符串在集合内 还是由集合内字符组成
思路:刚开始直接遍历找 发现不行
比如过不了这样一组样例
ab cd cdef
abcdef !会告诉我们找不到
实际上需要搜索 可以防止被前缀的干扰
下面是ac代码

#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define inf 0x3f3f3f3f
#define sd(a) scanf("%d",&a)
#define sdd(a,b) scanf("%d%d",&a,&b)
#define cl(a,b) memset(a,b,sizeof(a))
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define sddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define dbg() printf("aaa\n")
using namespace std;
int n,m;
string s;
set<string> st;
deque<string> q;
bool dfs(int p,string now,int len){
    now+=s[p];
    if(p==len-1){
        if(st.count(now)>0){
            q.push_back(now);
            return true;
        }
        return false;//没找到
    }
    bool flag=false;//找不到
    if(st.count(now)>0){
        q.push_back(now);
        if(dfs(p+1,"",len)) flag=true;
        if(flag) return true;
        q.pop_back();
    }
    return dfs(p+1,now,len);
}
int main() {
	int cnt=0;
    while(sd(n)!=EOF){
        if(n==0) break;
        st.clear();
        rep(i,1,n){
            cin>>s;
            st.insert(s);
        }
        cout<<"Data set #"<<++cnt<<":"<<endl;
        sd(m);
        rep(i,1,m){//对于每一个要检测的字符串
            cin>>s;
            if(st.count(s)>0){
                cout<<"     "<<s<<" --- the word is in dictionary"<<endl;
                continue;
            }
            int len=s.size();
            if(!dfs(0,"",len)){
                cout<<"     "<<s<<" --- misspelled word"<<endl;
            }else{
                cout<<"     "<<s<<" --- the word is concatenation of"<<endl;
                while(!q.empty()){
                    cout<<"          "<<q.front()<<endl;
                    q.pop_front();
                }
            }
        }
        cout<<endl;
    }
	return 0;
}
/*
ab cdef cd
abcdef

ab abcd ef
abcdef
*/

下面是题目
When people type very fast, they sometimes don’t hit the space key hard enough and miss the blank, e.g., instead of typing “sample word list”, they get “samplewordlist”. You are to write a program to first check whether a word appears in a dictionary. If it doesn’t, then you check to see if it appears as a concatenation of two or more words in the dictionary.

The Input:
There will be multiple date sets. The first input line for a data set will be an integer n(1<= n <= 50), indicating the number of words in a dictionary. Each of the following n input lines contains a word. Assume that each word contains only lower-case letters, is at least two letters and at most 20 letters, and starts in column 1. The next input line for the data set will be an integer m (m >= 1), indicating the number of words to be spell-checked. Each of the following m input lines contains a word. Assume that each word contains only lower-case letters, is at least two letters and at most 50 letters, and starts in column 1. End of data is indicated by a data set with a value of zero for n, i.e., a data set with a dictionary size of zero.

The output:
Print a heading for each data set. Then, print each word to be spell-checked and whether it is in the dictionary. If it is not in the dictionary, print whether it is a concatenation of two or more words in the dictionary and, if it is, print those words. If there is more than one combination of the words in the dictionary that will generate the word to be spell-checked, you only need to print one such combination and not all of them. If the word is not a combination of dictionary words either, print an error message. Leave a blank line after the output for each data set. Follow the format illustrated in Sample Output. Be sure to line up the output with spaces (not tabs) exactly as given in Sample Output.
样例输入
4
coaches
are
really
nice
5
are
reallyare
wrong
reallynicecoaches
wrongword
6
how
about
ali
is
nice
isnice
5
funfunfun
aboutali
ali
aliali
isnice
0
样例输出
Data set #1:
are — the word is in dictionary
reallyare — the word is concatenation of
really
are
wrong — misspelled word
reallynicecoaches — the word is concatenation of
really
nice
coaches
wrongword — misspelled word

Data set #2:
funfunfun — misspelled word
aboutali — the word is concatenation of
about
ali
ali — the word is in dictionary
aliali — the word is concatenation of
ali
ali
isnice — the word is in dictionary

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值