Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:额。。菜鸟求教。。c++的编译效率比g++要高么?

Posted by towelie at 2014-01-05 23:00:30 on Problem 1002 and last updated at 2014-01-05 23:25:18
In Reply To:额。。菜鸟求教。。c++的编译效率比g++要高么? Posted by:qianchen314 at 2014-01-04 04:53:01
If using g++, perhaps insert ' __attribute__((optimize("-O2"))) ' in your source code?


> 同样的代码用g++的时候就是TLE但是换成c++竟然通过了。。。。虽然时间是1.5s效率非常非常低。。
> 代码:
> #include <iostream>
> #include <iomanip>
> #include <locale>
> #include <sstream>
> #include <map>
> #include <string>
> using namespace std;
> 
> 
> 
> int stdnumber (const string & s)
> {
>   int size = s.size();
>   int result=0;
>   for (int i = 0; i<size; i++)
>     {
>       char aux = s[i];
>       if (aux == '-') continue;
>       else if (aux >= '0' && aux<= '9')
> 	result = result*10+aux-'0';
>       else if (aux >= 'A' && aux <= 'R')
> 	result= result *10 + ((aux-'A')/3+2);
>       else if (aux >= 'S' && aux <= 'Y')
> 	result = result * 10+((aux-'A' - 1) /3+2);
>       //cout<<aux<<" "<<result<<endl;
>     }
>   return result;
> }
> 
> int main (void)
> {
>   int length;
>   cin>> length;
>   map<int,int> dic;
>   bool duplicated = false;
>   string s;
>   for (int i =0 ; i< length ;i++)
>     {
>       cin>>s;
>       int number = stdnumber(s);
>       //cout<<number<<endl;
>       dic[number]++;
>     }
>   
>   for (map<int,int>::iterator it = dic.begin(); it != dic.end();it++)
>     {
> 
>       if (it-> second != 1)
> 	{
> 	  string str;
> 	  ostringstream convert;
> 	  convert<< (it->first);
> 	  str = convert.str();
> 	  for (int i = str.size();i<7;i++)
> 	    str.insert(0,1,'0');
> 	  //cout<<str<<endl;
> 	  duplicated = true;
> 	  cout<<(str.insert(3,1,'-'))<<" "<<it->second<<endl;
> 	}
>     }
>   if (!duplicated) cout<<"No duplicates. ";
>   
> }
> 

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator