Showing posts with label implementaion. Show all posts
Showing posts with label implementaion. Show all posts

Sunday, January 5, 2020

POJ.1003 Hangover

Problem:
http://poj.org/problem?id=1003

Idea:
n/a

Source:
 int main()  
 {  
      double d;  
      while (1) {  
           //scanf("%f", &d);  
           cin >> d;  
           if (d == 0.00) break;  
           int k;  
           double cur = 0.0;  
           for (k = 1; k < 3000; k++) {  
                cur += (1 / (double)(k + 1));  
                if (cur > d) break;  
           }  
           cout << k << " card(s)" << endl;  
      }  
      return 0;  
 }  

POJ.1007 DNA Sorting

Problem:
http://poj.org/problem?id=1007

Idea:
n/a

Source:
 int getInvs(string s)  
 {  
      int ans = 0;  
      int n = s.size();  
      for(int i=0;i<n;i++)  
           for (int j = i + 1; j < n; j++) {  
                if (s[i] > s[j]) ans++;  
           }  
      return ans;  
 }  
 bool comp(string a, string b)  
 {  
      return getInvs(a) < getInvs(b);  
 }  
 int main()  
 {  
      vector<string> sv;  
      int n, m;  
      cin >> m >> n;  
      for (int i = 0; i < n; i++) {  
           string s;  
           cin >> s;  
           sv.push_back(s);  
      }  
      sort(sv.begin(), sv.end(), comp);  
      for (int i = 0; i < n; i++) {  
           cout << sv[i] << endl;  
      }  
      return 0;  
 }  

Friday, January 3, 2020

POJ.1004 Financial Management


Problem Link:
http://poj.org/problem?id=1004

Idea:
n/a

Source:
 int main()  
 {  
  double d[12];  
  double sum = 0;  
  for (int i = 0; i < 12; i++) {  
  cin >> d[i];  
  sum += d[i];  
  }  
  cout << "$";  
  cout << fixed << std::setprecision(2) << sum / 12 << endl;  
  return 0;  
 }