现在的位置: 首页 > 综合 > 正文

Hackerrank Sherlock and The Beast

2018年02月20日 ⁄ 综合 ⁄ 共 271字 ⁄ 字号 评论关闭

一开始超时了 

#include <iostream>
#include <string>

using namespace std  ;

int main()
{
	int t ;
	cin >> t ;
	while (t--)
	{
		int n ;
		cin >> n ;
		string s ;
		for ( int i = n ; i >=0 ; --i)
		{
			if ( i%3 == 0 && (n-i) %5 == 0)
			{
				  
                for(int j=0;j<i;++j)
                    s+='5';
                for(int j=0;j<n-i;++j)
                    s+='3';
                break;
			}
	
		}
		if (s=="") cout << "-1" << endl ;
		else cout << s << endl ;
	}
	return 0 ;

抱歉!评论已关闭.