Login
Immutable PageDiscussionInfoAttachments
Diff for "rei05/C言語"

MMA
Differences between revisions 24 and 25
Revision 24 as of 2012-05-26 13:45:52
Size: 1108
Editor: rei05
Comment:
Revision 25 as of 2012-05-29 16:57:15
Size: 1188
Editor: rei05
Comment:
Deletions are marked like this. Additions are marked like this.
Line 15: Line 15:
 * [[/10028]]
Line 18: Line 19:
 * AOJ10026Wrong Answer
  * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=10026
 * AOJ10029Time Limit Exceeded
  * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=10029
Line 21: Line 22:
{{{ {{{#!highlight haskell
Line 23: Line 24:
#include<math.h>
Line 26: Line 26:
int n,s[1000],i,m1,m2;
double a;
int n,i,j,k,l,temp;
scanf("%d",&n);
Line 29: Line 29:
while(1){
  m1=0;m2=0;
  scanf("%d",&n); if(n==0) break;
  for(i=0;i<n;i++){
    scanf("%d",&s[i]);
    m1+=s[i];
int num[n];
for(i=0;i<n;i++){
  scanf("%d",&num[i]);
}

for(j=0;j<n;j++){
  for(k=0;k<j;k++){
    if(num[j]<num[k]){
      temp=num[j];
      num[j]=num[k];
      num[k]=temp;
    }
Line 36: Line 42:
  for(i=0;i<n;i++){
    m2+=pow(s[i]-m1/n,2);
  }
  a=fabs(sqrt(m2/n));
  printf("%f\n",a);
Line 42: Line 43:

for(l=0;l<n-1;l++){
  printf("%d ",num[l]);
}
printf("%d\n",num[n-1]);

C言語

AOJ解答

Help Me!

未解決

   1 #include<stdio.h>
   2 int main(){
   3 
   4 int n,i,j,k,l,temp;
   5 scanf("%d",&n);
   6 
   7 int num[n];
   8 for(i=0;i<n;i++){
   9   scanf("%d",&num[i]);
  10 }
  11 
  12 for(j=0;j<n;j++){
  13   for(k=0;k<j;k++){
  14     if(num[j]<num[k]){
  15       temp=num[j];
  16       num[j]=num[k];
  17       num[k]=temp;
  18     }
  19   }
  20 }
  21 
  22 for(l=0;l<n-1;l++){
  23   printf("%d ",num[l]);
  24 }
  25 printf("%d\n",num[n-1]);
  26 
  27 return(0);
  28 }
  • 16行目のm1/nの部分で結果が整数に丸められてる気がする。m1, m2をdoubleで定義するといい。 -- iz 2019-10-15 01:57:37

  • ご指摘の通り改善しましたところ正解でした。ありがとうございました。 -- rei05 2012-05-26 13:45:52

rei05/C言語 (last edited 2012-07-16 17:50:37 by nomeaning)