http://codeforces.com/contest/785/problem/A
一个简单的加法题,但是当你是用的是cin输入时时间是483ms而scanf时间被压缩到62ms
cin版
#include <iostream> #include<bits/stdc++.h> #include <malloc.h> using namespace std; //map<string,int>mp; //char ch[5]={'T','C','O','D','I'}; //int ch1[5]={4,6,8,12,20}; int main() { int n; string s; while(~scanf("%d",&n)) { int ans=0; for(int i=0;i<n;i++) { cin>>s; if(s[0]=='T') ans+=4; else if(s[0]=='C') ans+=6; else if(s[0]=='O') ans+=8; else if(s[0]=='D') ans+=12; else if(s[0]=='I') ans+=20; } printf("%d ",ans); } return 0; }
scanf版
#include <iostream> #include<bits/stdc++.h> #include <malloc.h> using namespace std; //map<string,int>mp; //char ch[5]={'T','C','O','D','I'}; //int ch1[5]={4,6,8,12,20}; int main() { int n; char s[100]; while(~scanf("%d",&n)) { int ans=0; for(int i=0;i<n;i++) { scanf("%s",s); if(s[0]=='T') ans+=4; else if(s[0]=='C') ans+=6; else if(s[0]=='O') ans+=8; else if(s[0]=='D') ans+=12; else if(s[0]=='I') ans+=20; } printf("%d ",ans); } return 0; }