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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章