posts - 99,  comments - 8,  trackbacks - 0
 
#include <iostream>
#
include <algorithm>
using namespace std;

int main ()
{
    int a[
1005];
    int t;
    scanf ( 
"%d"&t );
    
while ( t -- )
    {
          int n;
          scanf ( 
"%d"&n );
          
for ( int i = 0; i < n; i ++ )
          {
              scanf (
"%d"&a[i]);
          }
          sort ( a, a 
+ n );
          
          printf (
"%d", a[0]);
          
for ( int i = 1; i < n; i ++ )
          {
              printf (
" %d",a[i]);
          }
          printf (
"\n");
    } 
   
//system ("pause");
   
return 0;
}
简单的排序题,直接利用sort默认的排序规则:升序排列
posted @ 2010-09-06 21:19 雪黛依梦 阅读(278) | 评论 (0)编辑 收藏
为啥少了一个else 就错了呢?
//显然数据范围非常的大,测试a[10000]时已经无法正确的表示了
//要用用相关的知识进行处理 : ( a + b ) % 3 = ( a % 3 + b % 3% 3
#include <stdio.h>
#
include <stdlib.h>
#
include <string.h>

int a[
1000009];

int main ()
{
    int n;
    a[0] 
= 7 % 3;
    a[
1= 11 % 3;  
    
for ( int i = 2; i < 1000009; i ++ )
    {
        a[i] 
= ( a[i - 1+ a[i - 2] ) % 3;
    }
    
    
while ( scanf ("%d"&n) != EOF )
    {
          
if ( !a[n] )
             printf (
"yes\n");
          
else
           printf (
"no\n");
    }
    
//system ("pause");
    
return 0;
}
posted @ 2010-09-06 21:06 雪黛依梦 阅读(278) | 评论 (0)编辑 收藏
这是一道简单的数论知识题,即  a * b  =  gcd (a , b) * lcm (a,  b);
但是这里要注意一下如何求多个数的lcm  因为易在只有一个数的时候发生错误
#include <stdio.h>
#
include <stdlib.h>
#
include <string.h>
#
include <math.h>

int a[
100000];

int gcd ( int a, int b)
{
    
if ( b == 0 )
    
return  a;
    
else
    
return gcd ( b, a % b );
}

int lcm ( int a, int b )
{
    
return  a / gcd ( a, b )* b;
}

int main ()
{
    int t, m;
    scanf ( 
"%d"&t);
    
while ( t -- )
    {
       int temp;
       scanf (
"%d"&m);
       
       
//输入数据 
       
for ( int i = 0; i < m; i ++)
       {
          scanf (
"%d"&a[i]);
       }
       
//求值
       temp 
= a[0];
       
for ( int i = 1; i < m; i ++)
       {
        temp 
= lcm ( temp , a[i]);
       } 
       printf (
"%d\n", temp);
    }
    system (
"pause");
   
return 0;
}
posted @ 2010-09-06 20:31 雪黛依梦 阅读(526) | 评论 (0)编辑 收藏
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main ()
{
          int N;
          scanf ("%d", &N );
          for ( int i = 0; i < N; i ++ )
          {
              //输出之间存在空行 
              if (i)
              printf ("\n");
              
              int m, n;
              int num = 0;    //记录看这是第几组数   
              while ( scanf ("%d %d", &n, &m), m || n )           //水题也WA 了好多次就是这里错了
              {
                    num ++; 
                    int count = 0;    //用于记录满足条件的 a  b 整数对 
                    for ( int a = 1; a < n; a ++ )    //  b 
                    {
                        for ( int b = a + 1; b < n; b ++ )  // a
                        {
                            if ( (a * a + b * b + m) % ( a * b ) == 0 )      
                            count ++;
                        }
                    }
                    printf ("Case %d: %d\n", num, count);
              }
              
          }
 
   //system ("pause");
   return 0;
}
posted @ 2010-09-04 13:26 雪黛依梦 阅读(434) | 评论 (0)编辑 收藏

水题:只是格式好容易错的,像那个是从25 行输出,我的就变成了26

#include <stdio.h>
#
include <stdlib.h>
#
include <string.h>
#
include <math.h>

int a[
100000];
int main ()
{
    int step, mod;
    
    
while ( scanf ("%d %d"&step, &mod) != EOF )
    {  
          a[0] 
= 0;
          a[
1= ( a[0] + step) % mod;
          int k 
= 1
          
while ( a[k] != 0 )
          {
                k 
++;
                a[k] 
= ( a[k - 1+ step ) % mod;
          }

          
if ( k == mod )
          printf (
"%10d%10d    Good Choice\n", step, mod);
          
else
          printf (
"%10d%10d    Bad Choice\n",step, mod);
          printf (
"\n");
    }
    
//system ("pause");
    
return 0;
}
posted @ 2010-09-03 20:50 雪黛依梦 阅读(268) | 评论 (0)编辑 收藏
#include <stdio.h>
#
include <stdlib.h>
#
include <string.h>
#
include <math.h>

int f ( int n )
{
    int product 
= 1;
    
for ( int i = 1; i <= n; i ++ )
    {
        product 
*= i;
    }
    
return product;
}

int main ()
{
    double a[
10];
    a[0] 
= 1;
    
for ( int i = 1; i < 10; i ++ )
    {
        a[i] 
= 1.0 / f (i);  //求阶层的倒数 
    }

    double sum[
10];
    sum[0] 
= 1
    
for ( int i = 1; i < 10; i ++ )
    {
        sum[i] 
= sum[i - 1+ a[i];   //求和 
    }
    
    
    printf (
"n e\n");
    printf (
"- -----------\n");
    printf (
"0 1\n"); 
    printf (
"1 2\n"); 
    printf (
"2 2.5\n");
    
for ( int i = 3; i < 10; i ++)
    {
        printf (
"%d %.9f\n", i, sum[i]);
    }
    system (
"pause");
   
   
return 0;
}
posted @ 2010-09-03 19:15 雪黛依梦 阅读(259) | 评论 (0)编辑 收藏
#include <stdio.h>
#
include <stdlib.h>
#
include <string.h>
#
include <math.h>
int main ()
{
    int a[
1000];
    int n;
    
while ( scanf ("%d"&n) && n )
    {
          a[0] 
= 0;
          
for ( int i = 1; i <= n; i ++ )
          {
              scanf (
"%d"&a[i]);
          }
          
          int sum 
= 0;
          
for ( int i = 1; i <= n; i ++ )
          {
              
if ( a[i] > a[i - 1] )
              {
                   sum 
+= (a[i] - a[i - 1]) * 6 + 5;
              }
              
else if ( a[i] < a[i - 1])
              {
                   sum 
+= (a[i - 1- a[i]) * 4 + 5;
              }
              
else
              {
                  sum 
+= 5;
              }
          }
          
          printf (
"%d\n", sum);
    }
   system (
"pause");
   
return 0;
}
posted @ 2010-09-03 18:37 雪黛依梦 阅读(204) | 评论 (0)编辑 收藏
 #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main ()
{
    int n;
    char str[10000];
    while ( scanf ("%d", &n) != EOF && n )
    { 
          getchar ();         
          for ( int i = 0; i < n; i ++ )
          {
              scanf ("%s", &str);
              int len = 0;
              while ( str[len] != '\0')   //错点 
                    len ++;
                    
              int index = 0;
              while ( index < len )
              {
                  int count = 1;
                  if ( str[index] != str[index + 1] )
                  {
                       printf ("%c", str[index]);
                       index ++;
                  }          
                  else
                  {
                      count ++;
                      while (str[index] == str[ index + count])  //错点:是 ==  
                      count ++;
                      
                      printf ("%d%c", count, str[index]);
                      
                      index += count;
                  }
              }
              printf ("\n");
          }
    }

   return 0;
}
posted @ 2010-09-03 11:50 雪黛依梦 阅读(386) | 评论 (0)编辑 收藏

这道题的处理方法是把待处理的字符数组边界设为空格作为出口的标志,另设一个记录所走步数的数组steps,但是这个题目分两个走法,其一没有重复的路径,遇到空格后直接输出的步数,用mark = 0标记; 另一种情况就是出现了重复的路径也就是题目中if ( steps[curi][curj] != 0 )即下一步是已经走了的路径,那么这必然是循环的开始,根据记录的step和下一个step值之间的关系就可以输出

#include <iostream>
#
include <algorithm>
#
include <string>
using namespace std;

int main ()
{
    char map[
13][13];
    int steps[
13][13];
    int num, col, start;
    
while ( scanf ("%d %d %d"&num, &col, &start ) != EOF && ( num != 0 && col != 0 && start != 0 ) )
    {
          getchar ();
          memset (map, 0, sizeof(map) );
          memset (steps, 0, sizeof(steps) );
          
for ( int i = 0; i < col + 2; i ++ )
          {
              map[0][i] 
= ' ';
              map[num 
+ 1][i] = ' ';
          }
          
for ( int i = 0; i < num + 2; i ++ )
          {
              map[i][0] 
= ' ';
              map[i][col 
+ 1= ' ';
          }
          
for ( int i = 1; i <= num; i ++)
          {
              
for ( int j = 1; j <= col; j ++ )
              {
                  scanf (
"%c"&map[i][j]);
              }
              getchar ();
          }
          
          int step 
= 1;
          int curi 
= 1; int curj = start;
          int mark 
= 0;
          int temp 
= 1; int t = 0;
          
while ( map[curi][curj] != ' ' )
          {
                
if ( steps[curi][curj] != 0 )
                {
                     temp 
= step;
                     t 
= steps[curi][curj];
                     mark 
= 1;
                     
break;
                }
                
else
                {
                     steps[curi][curj] 
= step;
                     
if ( map[curi][curj] == 'N' )
                     {
                          curi 
= curi - 1;
                          curj 
= curj;
                     }
                     
else if ( map[curi][curj] == 'S' )
                     {
                          curi 
= curi + 1;
                          curj 
= curj;
                     }
                     
else if ( map[curi][curj] == 'W' )
                     {
                          curi 
= curi;
                          curj 
= curj - 1;
                     }
                     
else if ( map[curi][curj] == 'E' )
                     {
                          curi 
= curi;
                          curj 
= curj + 1;
                     }
                     
                    
                     step 
++;
                }               
          }
          
          
if ( mark == 0 )
          printf (
"%d step(s) to exit\n", step - 1 );
          
else
          printf (
"%d step(s) before a loop of %d step(s)\n", t - 1, temp - t );
          
    }
   
//system ("pause");
   
return 0;
}


 

posted @ 2010-08-30 15:28 雪黛依梦 阅读(339) | 评论 (0)编辑 收藏
#include <stdio.h>
#
include <stdlib.h>
#
define MAX 1001
#
define OK 1

int tag[MAX];  
//将出现了等号的(即真币)排除    标记为1   遍历时跳过 
int num[MAX];  
//记录下标为i的硬币在不等式的两边出现的次数 

int main ()
{
    
    int coin[MAX];   
//访问时下标的中介 
    int N, k, pi, count ;
    char c;
    
    
while ( scanf ("%d%d"&N, &k) != EOF )
    {
          count 
= 0;   //记录接下来的 k 次称量中有多少次出现了不等号 
          
          
for ( int i = 0; i < k; i ++)  // k 次的称量记录 
          {
              scanf (
"%d"&pi);
              
for (int j = 0; j < 2 * pi; j ++)
              {
                  scanf (
"%d"&coin[j]);
              }
              
              getchar ();
              
              c 
= getchar ();
              
              
for (int i = 0; i < 2 * pi; i ++)
              {
                  
if (c == '=')
                  tag[coin[i]] 
= 1;
                  
                  
else if (c == '<')
                  {
                       count 
++;
                       
for (int j = 0; j < pi; j ++)
                       { 
                           num[coin[j]]
--;
                       }
                       
for (int j = pi; j < 2 * pi; j++)
                       {
                           num[coin[j]]
++;
                       }
                  }
                  
                  
else
                  {
                      count 
++;
                       
for (int j = 0; j < pi; j ++)
                       {
                           num[coin[j]]
++;
                       }
                       
for (int j = pi; j < 2 * pi; j++)
                       {
                           num[coin[j]]
--;
                       }
                  }
              }
             
          }
          
          int mark 
= 0;
          int temp ;
          
for (int i = 1; i <= N; i ++)
          {
              
if (tag[i] == 1)  //表示为真币,不可能 
              
continue;
              
              
if (num[i] == count || num[i] == -count)   //如果硬币在不等式的两边出现的次数等于不等号数为假币 
              {
                         mark 
++;
                         temp 
= i;
              }
          }
          
          
if (mark == 1)    // 假币只有一个 
          {
             printf (
"%d\n", temp);
          }
          
          
else 
          printf (
"%d\n",0);
            
    }
    
    
return 0;
}
posted @ 2010-08-29 11:49 雪黛依梦 阅读(407) | 评论 (0)编辑 收藏
仅列出标题
共10页: 1 2 3 4 5 6 7 8 9 Last 
<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

常用链接

留言簿(4)

随笔分类

随笔档案

文章档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜