zoukankan      html  css  js  c++  java
  • 11.7

      1 void base1(int b,int n)
      2 {
      3   int i=0,a[10];
      4   memset(a,0,sizeof(a));
      5   assert(2<=b<=10);
      6   while(n>=b)
      7    { a[i++]=n%b;
      8   n=n/b;
      9    }
     10 a[i]=n;
     11 for(i;i>=0;i--)
     12 printf("%d
    ",a[i]);
     13 }
     14 void base2(int b,int n)
     15 {
     16   int i=0,j=0,z=b;
     17     i=n%10;
     18        n=n/10;
     19       j=j+i;
     20 
     21   while(n>0)
     22     {
     23        i=n%10;
     24        n=n/10;
     25       j=j+i*z;
     26       z=z*b;
     27     }
     28   printf("%d
    ",j);
     29 }
     30 
     31 void word(char *a)
     32 {
     33   /* char buf[]="c programmer"; */
     34   /* word(buf); */
     35   /* 注意几个问题 strlen只要数组名就可以了 */
     36   /* 声明一个字符串数组也不需要先规定数组的大小 */
     37   /* 调用的时候也只要数组名 */
     38   int i;
     39       double j=0.0,z=0.0;
     40   for(i=0;i<=strlen(a);i++)
     41     {
     42       if(isalpha(a[i]))
     43     j++;
     44       else z++;
     45     }
     46   printf("%.3f
    ",j/z);
     47 }
     48 
     49 void product()
     50 {
     51   int x=0,i=0,j=0;
     52   int b=1,a[10];
     53   /* while(scanf("%d",&x)==1) */
     54   /*   { */
     55   /*     if(isdigit(x))     scanf输入都变成了字符串了*/
     56     /* a[i++]=x; */
     57   /*   } */
     58   /* while(i>=0) */
     59   /*   b=b*a[i--]; */
     60   /* printf("%d
    ",b); */
     61   /*  */
     62   /* 这题的思路将输入的字符串分类,如果是数字就提出出来,并且只需要计算输入的后三位 */
     63   int result=0,newdata=0,counts=0;
     64   memset(a,0,sizeof(a));
     65   while(scanf("%s",a)!=0)
     66     {
     67       if(a[0]>='A'&&a[0]<='Z')
     68     continue;
     69       counts=counts+1;
     70       if(counts==1)
     71     result=1;
     72       int p=strlen(a)-1;
     73       newdata =0;
     74       if(p>=0&&a[p]<='0'&&a[p]>='9')
     75     newdata=(a[p]-'0');
     76       p=p-1;
     77 if(p>=0&&a[p]<='0'&&a[p]>='9')
     78     newdata=(a[p]-'0')*10;
     79       p=p-1;
     80 if(p>=0&&a[p]<='0'&&a[p]>='9')
     81     newdata=(a[p]-'0')*100;
     82 
     83 
     84     }
     85   result=(result*newdata)%1000;
     86   printf("%d",result);
     87 }
     88 
     89 
     90 void rotate()
     91 {
     92   int n,i,j;
     93   char a[100][100];
     94   freopen("data.in","r",stdin);
     95   freopen("data.out","w",stdout);
     96   scanf("%d",&n);
     97   for(i=0;i<n;i++)
     98     for(j=0;j<n;j++)
     99       {
    100     scanf("%c",&a[i][j]);
    101     while(a[i][j]=='
    ' || a[i][j]=='	'|| a[i][j]==' ' )
    102       scanf("%c",&a[i][j]);
    103       }
    104   for(i=0;i<n;i++)
    105     { for(j=0;j<n;j++)
    106 printf("%c",a[i][j]);
    107    
    108 printf("
    ");
    109 
    110 }
    111 }

     今天内容

    学会用常量表简化代码量

    学会用状态量辅助字符串读入

    从标准输入中读取一行包含空格

    从文件中读入一行字符串其中包含空格

  • 相关阅读:
    HTML5触摸屏touch事件使用介绍1
    hdu 1408 acdearm &quot;Money, Money, Money&quot;
    基于QTP的自己主动化測试框架介绍
    ExpandListView onChildClickListener 失效
    hdu1227 Fast Food
    Linux C高级编程——文件操作之系统调用
    nodejs之路-[0]安装及简易配置
    动态加入改动删除html表格内容
    socket网络编程基础小记
    LeetCode OJ Minimum Depth of Binary Tree 递归求解
  • 原文地址:https://www.cnblogs.com/been/p/4081093.html
Copyright © 2011-2022 走看看