Gas Price Is Going Up/Down[模拟]

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
   

我也不知道为啥,反正它错了

模拟,先搞出来normal,再搞plus,最后搞super。一位一位的搞。

错误代码:

#include<iostream>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<vector>
#include<queue>
#include<array>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
const int mod=10^9+7;
//tuple<int,int,int>p[100000]
//char mat[20][20];
string price(string s,string t)
{
    string ans;
    if(t[0]!='-'&&t[1]!='-'&&t[2]!='-')
        return t;
    if(t[0]=='-'&&t[1]!='-'&&t[2]!='-')
    {
        ans=t[1];
        ans+=t[2];
        if(t[1]>s[1]||(t[1]==s[1]&&t[2]>s[2]))
            ans=s[0]+ans;
        else
            ans=(char)(s[0]+1)+ans;
    }
    if(t[0]!='-'&&t[1]=='-'&&t[2]!='-')
    {
        ans=t[0];
        if(t[0]>s[0])
        {
            ans+='0';
            ans+=t[2];
        }
        else
        {
            if(t[2]>s[2])
            {
                ans+=s[1];
                ans+=t[2];
            }
            else
            {
                ans+=(char)(s[1]+1)+t[2];
            }
        }
    }
    if(t[0]!='-'&&t[1]!='-'&&t[2]=='-')
    {
        ans+=t[0];
        ans+=t[1];
        if(t[0]>s[0]||t[1]>s[1])
            ans+='0';
        else
            ans+=(char)(s[2]+1);
    }
    return  ans;
}
int main()
{
    int n;
    scanf("%d",&n);
    int T=1;
    while(T<=n)
    {
        string nomal,plus,super;
        cin>>nomal>>plus>>super;
        string a="",b="",c="";
        if(nomal[0]=='-')
            a+='2';
        else
            a+=nomal[0];
        if(nomal[1]=='-')
            a+='0';
        else
            a+=nomal[1];
        if(nomal[2]=='-')
            a+='0';
        else
            a+=nomal[2];
        b=price(a,plus);
        c=price(b,super);
        printf("Gas Station #%d:\n",T);
        printf("   Input:  ");
        cout<<nomal<<" "<<plus<<" "<<super<<endl;
        printf("   Output: ");
        cout<<a<<" "<<b<<" "<<c<<endl;
        cout<<endl;
        T++;
    }
    return 0;
}

ac代码:

#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <cstdio>
#include <algorithm>
#define INF 0x3f3f3f3f
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int mod=1e9+7;
const int maxn=5e4+10;
const double pi=3.14159;

string change(string s, string t) {
	string ans;
	if (t[0]!='-' && t[1]!='-' && t[2]!='-') {
		return t;
	}
	if (t[0]=='-' && t[1]!='-' && t[2]!='-') {
		ans=t[1];
		ans+=t[2];
		if (t[1]>s[1] || (t[1]==s[1] && t[2]>s[2])) 
			ans=s[0]+ans;
		else ans=(char)(s[0]+1)+ans;
	}
	if (t[0]!='-' && t[1]=='-' && t[2]!='-') {
		ans=t[0];
		if (t[0]>s[0]) {
			ans+='0';
			ans+=t[2];
		} else {
			if (t[2]>s[2]) {
				ans+=s[1];
				ans+=t[2];
			} else {
				ans+=(char)(s[1]+1);
				ans+=t[2];
			}
		}
	}
	if (t[0]!='-' && t[1]!='-' && t[2]=='-') {
		ans=t[0];
		ans+=t[1];
		if (t[1]>s[1] || t[0]>s[0])
			ans=ans+'0';
		else  ans=ans+(char)(s[2]+1);
	}
	return ans;
}
int main() {

	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T;
	cin>>T;
	int ca=1;
	while (T--) {
		string a,b,c;
		cin>>a>>b>>c;
		string na="",nb="",nc="";
		if (a[0]=='-') na+='2';
		else na+=a[0];
		if (a[1]=='-') na+='0';
		else na+=a[1];
		if (a[2]=='-') na+='0';
		else na+=a[2];
		nb=change(na,b);
		nc=change(nb,c);
		cout<<"Gas Station #"<<ca++<<":"<<endl;
		cout<<"   Input:  "<<a<<" "<<b<<" "<<c<<endl;
		cout<<"   Output: "<<na<<" "<<nb<<" "<<nc<<endl;
		cout<<endl;
	}
	return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值