Lazy Cancer patients Simple Tool Series | C++

Source: Internet
Author: User

Here are some small tools for things you can do but don't bother to do. Code difficulty is not very large , in fact, mainly to their lazy use .

Probably will continue to update/maintenance, there are pits welcome to put forward, anyway, I am too lazy to change . Content with my brain hole diameter of + +, lazy degree of + + and code Force + + will continue to + +.

1. Integer Open 2-party

Example input: 12

Sample output: 2√3

Code:

1#include <cstdio>2#include <iostream>3#include <cstring>4 using namespacestd;5 inta[200000];6 intMain ()7 {8     intN,i=0, now=2, ans=1, w=1;9scanf"%d",&n);Ten      while(n!=1) { One          while(n%now==0) { Aa[++i]=Now ; -n=n/Now ; -         } thenow++; -     } -     intm=I,en; -I=1; +      while(i<=m) { -         intp=A[i]; +en=0; A          while(a[i]==p) { ati++; -en++; -         } -         if(en%2!=0) { -              for(intj=1; j<=en/2; J + +) w=w*p; -ans*=p; in}Else  for(intj=1; j<=en/2; J + +) w=w*p; -     } to     if(ans==1) { +cout<<w<<Endl; -}Else { thecout<<w<<"√"<<ans<<Endl; *     } $     return 0;Panax Notoginseng}
integer Open 2-side

2. Calculate the number of people, median, average, variance

Content: Normal data: Enter N, and then enter n wait statistics, weighted data: Enter W, and then enter the W group, A, a B.

Output in turn: number, median, average, variance.

1#include <cstdio>2#include <iostream>3#include <cstring>4#include <algorithm>5#include <cmath>6 using namespacestd;7 DoublePing,fangcha,mid,all=0, pk=0;8 inta[20000],bo[200100],zhong[101];9 intMain ()Ten { Oneprintf"First enter 1 or 2, 1 means that the next input data is normal data, 2 means that the input data is weighted data,"); Aprintf"The weighted data input method is input W for the first W group, followed by the W Group A B for each group of a b\n");  -Memset (Bo,0,sizeof(bo)); -     intn=0, maxn=-1, maxx=-1, t=0, b,w,v=0, L,r; theCin>>b; -     if(b==1) { -scanf"%d",&n); -          for(intI=1; i<=n; i++) { +scanf"%d",&a[i]); -             if(A[I]&GT;MAXN) maxn=A[i]; +all+=A[i]; Abo[a[i]]++; at         } -}Else { -scanf"%d",&W); -          for(intI=1; i<=w; i++) { -scanf"%d%d",&l,&R); -n+=l; in              for(intj=1; j<=l; J + +) a[++v]=R; -             if(A[V]&GT;MAXN) maxn=A[v]; toall+=a[v]*l; +bo[a[v]]=l; -         } the     } *      $      for(intI=1; i<=maxn; i++)if(Bo[i]>maxx) maxx=Bo[i];Panax Notoginseng      for(intI=1; i<=maxn; i++)if(bo[i]==Maxx) { -t++; thezhong[t]=i; +     } ASort (A +1, a+n+1); the     if(n%2!=0) mid=a[(n+1)/2];ElseMid= (a[n/2]+a[n/2+1])/2.0; +ping=all/n*1.0; -      for(intI=1; i<=n; i++) pk+= (Ping-a[i]) * (ping-a[i]); $fangcha=pk/n*1.0; $printf"The majority of the numbers are:"); -     if(t!=n) for(intI=1; i<=t; i++) printf ("%d", Zhong[i]);Elsecout<<"no number ."; -printf"\ n"); theprintf"Median :%.2f\n", mid); -printf"The average is:%.2f\n", ping);Wuyiprintf"Variance is:%.2f\n", Fangcha); the GetChar (); -     return 0; Wu}
Four statistical calculations

It was almost a hole in the beginning and had been modified.

Repair in ...

Lazy Cancer patients Simple Tool Series | C++

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.