/* user: php time: 0.008 sec link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1199 */ #include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<algorithm> #include<vector> #include<string> #include<stack> #include<queue> #include<map> #include<sstream> #define FOR(i, s, e) for(int i=s; i<e; i++) #define loop(i, n) for(int i=0; i<n; i++) #define getint(n) scanf("%d", &n) #define pb(a) push_back(a) #define ll long long #define SZ(a) int(a.size()) #define read() freopen("input.txt", "r", stdin) #define write() freopen("output.txt", "w", stdout) #define mem(a, v) memset(a, v, sizeof(a)) #define all(v) v.begin(), v.end() #define pi acos(-1.0) #define INF 1<<29 #define mod(a) (a>0?a:-a) #define pf printf #define sf scanf using namespace std; bool attendedteam[101]; struct DATA{ int id; ll total; ll tried[10]; bool solved[10]; int totalsolved; }; DATA teamdata[101]; bool comp(DATA a, DATA b) { if(b.totalsolved > a.totalsolved) { return false; } else if(a.totalsolved == b.totalsolved) { if(a.total < b.total) { return true; } else { return a.id < b.id; } } else { return true; } } int main() { bool blank = false; FOR(i, 1, 101) { teamdata[i].id = i; } int kases; getint(kases); cin.ignore(); cin.ignore(); stringstream ss; string str; int teamid, probid, timesplit; char verdict; while(kases--) { if(blank) pf("\n"); blank = true; mem(attendedteam, 0); FOR(i, 1, 101) { teamdata[i].total = 0; teamdata[i].totalsolved = 0; FOR(j, 1, 10) { teamdata[i].tried[j] = 0; teamdata[i].solved[j] = 0; } } while(true) { getline(cin, str); if(SZ(str) == 0) break; ss.clear(); ss<<str; ss>>teamid>>probid>>timesplit>>verdict; attendedteam[teamid] = 1; if(teamdata[teamid].solved[probid] == 0) { if(verdict == 'C' ) { teamdata[teamid].totalsolved++; teamdata[teamid].solved[probid] = 1; teamdata[teamid].total += teamdata[teamid].tried[probid] + timesplit; } else if(verdict == 'I') { teamdata[teamid].tried[probid] += 20; } } } vector<DATA>v; FOR(i, 1, 101) { if(attendedteam[i]) { v.pb(teamdata[i]); } } sort(all(v), comp); int len = SZ(v); loop(i, len) { pf("%d %d %lld\n", v[i].id, v[i].totalsolved, v[i].total); } } return 0; }
Category Archives: Contest
Scanf and Printf for Double Variable
0For printing and scanning double variables we must to use %lf, not %llf. I must must remember this in contest and problem solving time!! It can ruin my life!!!
My C++ Code Template
0#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<algorithm> #include<vector> #include<queue> #include<stack> #include<map> #include<utility> #include<set> #define FOR(i, s, e) for(int i=s; i<e; i++) #define loop(i, n) FOR(i, 0, n) #define sf scanf #define pf printf #define pb push_back #define MP make_pair #define fr first #define sc second #define ll long long #define dd double #define all(v) v.begin(), v.end() #define PI acos(-1.0) #define mem(ara, value) memset(ara, value, sizeof(ara)) #define paii pair<int, int> #define pall pair<ll, ll> #define SZ(a) int(a.size()) #define read(nm) freopen(nm, "r", stdin) #define write(nm) freopen(nm, "w", stdout) #define dump(x) cout<<#x<<" = "<<x<<endl using namespace std; #define take(args...) asdf,args #define debug(args...) asdfg,args; cout<<endl struct ASDF{ ASDF& operator,(int &a) { sf("%d", &a); return *this; } ASDF& operator,(long int &a){ sf("%ld", &a); return *this; } ASDF& operator,(long long int &a){ sf("%lld", &a); return *this; } ASDF& operator,(char &c){ sf("%c", &c); return *this; } ASDF& operator,(double &d){ sf("%lf", &d); return *this; } template<typename T> ASDF& operator,(T &a){ cin>>a; return *this; } }asdf; struct ASDFG{ template<typename T> ASDFG& operator,(vector<T> &v){ pf("["); cout<<v[0]; FOR(i, 1, SZ(v)){ cout<<", "<<v[i]; } pf("]"); return *this; } template<typename T> ASDFG& operator,(T x) { cout<<x<<" "; return *this; } }asdfg; //Header ends here int main() { return 0; }
PHP Standard I/O (for Contest)
0<?php if($_SERVER['HTTP_HOST'] == '127.0.0.1') { $file = fopen('input.txt', 'r'); } else { $file = STDIN; } while(($line = fgets($file)) !== false) { $line = trim($line); if($line == 42) break; echo $line . "\n"; } ?>