UVA - 621 - Secret Research

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=99&page=show_problem&problem=562


题意:

    输入字符串S,根据字符串规则,判定后输出。

    S = 1 或 S = 4 或S = 78时,输出“+”。

    S = *35时(*表示任意),输出“-”。

    S = 9*4时(*表示任意),输出“*”。

    S = 190*时(*表示任意),输出“?”。


解题:

    前面做了两道题,老以为这个也是要推导,结果不理解题意,跑去看别人题解才知道水。。。


#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;

// #define LOCAL_TEST


int main()
{
#ifdef LOCAL_TEST
	freopen("f:\\in.txt", "r", stdin);
	freopen("f:\\out.txt", "w+", stdout);
#endif
	int nCases;
	cin >>nCases;
	cin.ignore();

	while ( nCases-- )
	{
		char strIn[100000];
		gets(strIn);
		string str(strIn);
		if ( str == "1" || str == "4" || str == "78" )
		{
			cout <<'+' <<'\n';
			continue;
		} // end if
		if ( str.substr(str.length()-2) == "35" )
		{
			cout <<'-' <<'\n';
			continue;
		} // end if
		if ( str.at(0) == '9' && str.at(str.length()-1) == '4' )
		{
			cout <<'*' <<'\n';
			continue;
		} // end if
		if ( str.substr(0, 3) == "190" )
		{
			cout <<'?' <<'\n';
			continue;
		} // end if
	} // end while

	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值