| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:额。。菜鸟求教。。c++的编译效率比g++要高么?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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator