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

MMA
Differences between revisions 1 and 29 (spanning 28 versions)
Revision 1 as of 2012-05-08 17:39:22
Size: 443
Editor: rei05
Comment:
Revision 29 as of 2012-06-01 16:54:19
Size: 1449
Editor: rei05
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
=Help Me!= = C言語 =
== AOJ解答 ==
 . 最終的にAcceptedとなった回答です。
Line 3: Line 5:
 * AOJ10020番、WrongAnswer  . ここはこうした方がいいなど改善すべき点がありましたら是非ご教授お願いします。
Line 5: Line 7:
#Comment  * [[/10020]]
 * [[/10021]]
 * [[/10022]]
 * [[/10023]]
 * [[/10024]]
 * [[/10025]]
 * [[/10026]]
 * [[/10027]]
 * [[/10028]]
 * [[/10030]]
Line 7: Line 18:
{{{
#include<stdio.h>
== Help Me! ==
=== 未解決 ===
 * AOJ10029番 Time Limit Exceeded
  * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=10029
Line 10: Line 23:
int main(){
Line 12: Line 24:
int num,i,pri;
char ch,counter[256]={0};
Line 15: Line 25:
while(1){
  scanf("%c",&ch);
    if(ch=='\n') break;
  if('a'<=ch&&ch<='z'){
    num=ch-'a';
    counter[num]++;
  }else if('A'<=ch&&ch<='Z'){
    num=ch-'A';
    counter[num]++;
  }
 * [[/Discussion]]
  * クイックソートで書いてみましたがTime Limit Exceeded。おかしな箇所を教えてください。-- [[rei05]] <<DateTime(2012-06-01T16:54:19+0900)>>

{{{#!highlight haskell
#include <stdio.h>

void Sort(int num[],int left,int right);

int main()
{
 int n,i;
 scanf("%d",&n);
 int num[n];

 for(i=0;i<n;i++)
  scanf("%d",&num[i]);

 Sort(num,0,n-1);

 for(i=0;i<n;i++)
  printf("%d ",num[i]);
 printf("\n");

 return(0);
Line 27: Line 51:
for(i=0;i<=25;i++){
  pri=counter[i];
  printf("%c : %d\n",i+'a',pri);
}
void Sort(int num[],int left,int right)
{
 int i,j,temp;
 int center=(left+right)/2;
Line 32: Line 56:
return(0);  while(1){
  i=left;
  j=right;

  while(num[i]<num[center])
   i++;
  while(num[center]<num[j])
   j--;
  if(i==j)
   break;
  if(num[i]==num[j]){
   i++;
   if(i==j)
    break;
  }

  temp=num[i];
  num[i]=num[j];
  num[j]=temp;
 }

 if(center-left>=2)
  Sort(num,left,center-1);
 if(right-center>=2)
  Sort(num,center+1,right);

C言語

AOJ解答

Help Me!

未解決

   1 #include  <stdio.h>
   2 
   3 void Sort(int num[],int left,int right); 
   4 
   5 int main()
   6 {
   7         int n,i;
   8         scanf("%d",&n);
   9         int num[n];
  10 
  11         for(i=0;i<n;i++)
  12                 scanf("%d",&num[i]);
  13 
  14         Sort(num,0,n-1);
  15 
  16         for(i=0;i<n;i++)
  17                 printf("%d ",num[i]);
  18         printf("\n");
  19 
  20         return(0);
  21 }
  22 
  23 void Sort(int num[],int left,int right)
  24 {
  25         int i,j,temp;
  26         int center=(left+right)/2;
  27 
  28         while(1){
  29                 i=left;
  30                 j=right;
  31 
  32                 while(num[i]<num[center])
  33                         i++;
  34                 while(num[center]<num[j])
  35                         j--;
  36                 if(i==j)
  37                         break;
  38                 if(num[i]==num[j]){
  39                         i++;
  40                         if(i==j)
  41                                 break;
  42                 }
  43 
  44                 temp=num[i];
  45                 num[i]=num[j];
  46                 num[j]=temp;
  47         }
  48 
  49         if(center-left>=2)
  50                 Sort(num,left,center-1);
  51         if(right-center>=2)
  52                 Sort(num,center+1,right);
  53 }

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