|
|
вернуться в форумC++ program!!! #include <iostream> #include <stdio.h> using namespace std; int main() { int br[10024],i,m; double n,a; float sum; cin>>n>>a; sum=100/a; for(i=1;i<=10024;i++) { br[i]=0; } for(i=1;i<=a;i++) { cin>>m; br[m]++; } for(i=1;i<=n;i++) {
printf("%.2lf",(br[i]*sum)); cout<<"%"<<endl; } return 0; } Re: C++ program!!! #include <iostream> #include <hash_map> using namespace std; int main(){ int N = 0, M = 0, temp = 0; cin>>N>>M; hash_map<int, int> hm; for(int i = 1; i < N + 1; i++){ hm.insert(make_pair(i, 0)); } for(int i = 1; i < M + 1; i++){ cin>>temp; hash_map<int, int>::iterator it = hm.begin(); it = hm.find(temp); (it->second)++; } for(int i = 1; i < N + 1; i++){ hash_map<int, int>::iterator it = hm.begin(); it = hm.find(i); int value = it->second; float value_ = value; float M_ = M; printf("%.2f", 100.0 * value/M_); cout<<"%"<<endl; } } Re: C++ program!!! #include <iostream> using namespace std; int main () { int a[10000],n,m,i,j; float p,br=0; cin>>n>>m; for (i=1;i<=m;i++) cin>>a[i]; for (i=1;i<=n;i++) { for (j=1;j<=m;j++) if (i==a[j]) br++; p=br/m; p=p*100; printf("%.2lf",p); cout<<"%"<<endl; br=0; } return 0; } Re: C++ program!!! Why it does not work? #include <iostream> #include <iomanip> using namespace std; int main(){ int N,M; cin>>N; cin>>M; double* arr= new double[N]; int i=0; int voice; while(i<M){ cin>>voice; arr[voice-1]=arr[voice-1]+1; i++; } i=0; while(i<N){ double s = arr[i]/M*100; cout<<fixed<<setprecision(2)<<s<<'%'<<endl; i++; } return 0; } Edited by author 29.04.2013 18:02 Re: C++ program!!! Послано ELDVN 1 ноя 2015 17:04 My solution: #include <iostream> #include <string> #include <vector> #include <set> #include <queue> #include <map> #include <stack> #include <algorithm> #include <bitset> #include <cstring> #include <cmath> #include <cstdlib> #include <cstdio> #include <iomanip> #define F first #define S second #define ll long long #define len length() #define sqr(x) x*x #define pb push_back #define mp make_pair #define sz(x) ((int) (x).size()) #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() #define bp(x) __builtin_popcount(x) #define INF numeric_limits<long long int>::max() #define frp freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++) const int maxn = (int)1e6; const int mod = (int)1e9 + 7; using namespace std; int n, m; int a[100110]; main(){ scanf("%d%d",&n,&m); for(int i=1; i <= m; i++){ int x; scanf("%d",&x); a[x]++; } for(int i=1; i <= n; i++){ printf("%.2lf",a[i]*100.0/m); puts("%"); }
return 0; } |
|
|