牛客练习赛34 A little w and Soda

题目链接

两元一瓶汽水,两个汽水瓶可以换一瓶汽水。也就是说一个汽水瓶的价值是 1 元钱。

最后可以借一个空瓶,所以最后手里不会剩下空瓶。那么一开始能花掉多少钱,最后 就能够喝到多少汽水。

所以奇数会剩下一块钱花不出去,偶数最后不会有剩余。答案为奇数-1,偶数直接输 出。

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string.h>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<vector>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
const int maxn =100+5;
const int maxm=10000;
const int mod =1e9+7;
const int INF=0x3f3f3f3f;
const double eps=1e-8;

int main()
{
	int t;scanf("%d",&t);
	while(t--)
	{
		char s[maxn];
		scanf("%s",s);
		int len=strlen(s);
		if((s[len-1]-'0')&1)
		{
			for(int i=0;i<len-1;i++)
				cout<<s[i];
			cout<<s[len-1]-'0'-1<<endl;
		}
		else
		{
			for(int i=0;i<len;i++)
				cout<<s[i];
			cout<<endl;
		}
	}
    return 0;
}

猜你喜欢

转载自blog.csdn.net/wzazzy/article/details/85010755