#include <bits/stdc++.h>
#define LL long long
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<n;i++)
#define REV(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define pri(a) cout<<a<<endl
#define prii(a,b) cout<<a<<" "<<b<<endl
using namespace std;
int main()
{
int T;
string s;
cin>>T;
getchar();
getchar();
while(T--)
{
map <string, int> mp;
set <string> st;
int cnt = 0;
while(getline(cin,s) and s[0])
{
mp[s]++;
cnt++;
st.insert(s);
}
set<string> :: iterator it;
for(it=st.begin(); it!=st.end(); it++)
{
double xx = (double) (mp[*it]*100)/cnt;
cout << *it << " " << fixed << setprecision(4) << xx << "\n";
}
if(T) puts("");
mp.clear();
st.clear();
}
return 0;
}
~Be glad of life because it gives you the chance to love and to work and to play and to look at the stars.~
Sunday, May 22, 2016
UVa 11340 Newspaper
#include <bits/stdc++.h>
#define LL long long
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<n;i++)
#define REV(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define pri(a) cout<<a<<endl
#define prii(a,b) cout<<a<<" "<<b<<endl
using namespace std;
int main()
{
int T,n, hi,x;
string s;
char ch;
cin>>T;
while(T--)
{
map <char, int> mp;
cin>>hi;
while(hi--)
{
cin>>ch>>n;
mp[ch] = n;
}
int cnt = 0;
cin>>x;
getchar();
while(x--)
{
getline(cin,s);
REP(i,SZ(s))
{
cnt += mp[ s[i] ];
}
}
double xx = (double) (cnt*1.0/100);
cout << fixed << setprecision(2) << xx << '$' << "\n";
}
return 0;
}
#define LL long long
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<n;i++)
#define REV(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define pri(a) cout<<a<<endl
#define prii(a,b) cout<<a<<" "<<b<<endl
using namespace std;
int main()
{
int T,n, hi,x;
string s;
char ch;
cin>>T;
while(T--)
{
map <char, int> mp;
cin>>hi;
while(hi--)
{
cin>>ch>>n;
mp[ch] = n;
}
int cnt = 0;
cin>>x;
getchar();
while(x--)
{
getline(cin,s);
REP(i,SZ(s))
{
cnt += mp[ s[i] ];
}
}
double xx = (double) (cnt*1.0/100);
cout << fixed << setprecision(2) << xx << '$' << "\n";
}
return 0;
}
Saturday, May 14, 2016
UVa 355 - The Bases Are Loaded
#include <bits/stdc++.h>
#define LL long long
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define REV(i,n) for(int i=n-1;i>=0;i--)
#define pri(a) cout << a << endl;
#define prii(a,b) cout << a << " " << b << endl;
using namespace std;
bool isoka(string s, int bp)
{
int tmp;
REP(i,SZ(s))
{
tmp = isdigit(s[i]) ? s[i] - '0' : s[i] - 55; //***
if(tmp >= bp) return 0; //*** Invalid Number of Any Base
}
return 1;
}
int main()
{
int bp, bt;
string s;
while(cin>>bp>>bt>>s)
{
if(!isoka(s,bp))
{
printf("%s is an illegal base %d number\n", s.c_str(), bp);
}
else
{
LL dec = strtoll(s.c_str(), NULL, bp); //*** String to Decimal Auto Convert
string tst = "";
while(dec)
{
tst += (dec%bt <= 9) ? dec%bt + '0' : dec%bt + 55; //*** Mod and Divide -- Dec2AnyBaseConvert
dec /= bt;
}
if(!SZ(tst)) tst += "0"; //***
reverse(ALL(tst));
printf("%s base %d = %s base %d\n", s.c_str(), bp, tst.c_str(), bt);
}
}
return 0;
}
#define LL long long
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define REV(i,n) for(int i=n-1;i>=0;i--)
#define pri(a) cout << a << endl;
#define prii(a,b) cout << a << " " << b << endl;
using namespace std;
bool isoka(string s, int bp)
{
int tmp;
REP(i,SZ(s))
{
tmp = isdigit(s[i]) ? s[i] - '0' : s[i] - 55; //***
if(tmp >= bp) return 0; //*** Invalid Number of Any Base
}
return 1;
}
int main()
{
int bp, bt;
string s;
while(cin>>bp>>bt>>s)
{
if(!isoka(s,bp))
{
printf("%s is an illegal base %d number\n", s.c_str(), bp);
}
else
{
LL dec = strtoll(s.c_str(), NULL, bp); //*** String to Decimal Auto Convert
string tst = "";
while(dec)
{
tst += (dec%bt <= 9) ? dec%bt + '0' : dec%bt + 55; //*** Mod and Divide -- Dec2AnyBaseConvert
dec /= bt;
}
if(!SZ(tst)) tst += "0"; //***
reverse(ALL(tst));
printf("%s base %d = %s base %d\n", s.c_str(), bp, tst.c_str(), bt);
}
}
return 0;
}
Subscribe to:
Posts (Atom)