zoukankan      html  css  js  c++  java
  • HDU 1200 To and Pro

    水题一道,考得就是英语吧···

    不过最近才做出来,觉得自己平时太懒了。

    题意:给出一个字母矩形,给出已知列,将矩阵以列逐列向右读,输出字符串。

    思路:本来想做一个倒置矩阵。将相应行倒置。去年的时候接触这题大概是想用数学位置解决的,当时做不出来。

         其实直接在已知字符串上做转置就行了,关键函数:reverse(p,p+n)

     1 #include <stdio.h>
     2 #include <cstring>
     3 #include <algorithm>
     4 using namespace std;
     5 
     6 char ch[30][40];
     7 int cnt = 0 , n;
     8 char str[300];
     9 
    10 void output()
    11 {
    12     for(int j=0;j<n;j++)
    13     {
    14         for(int i=0;i<cnt;i++)
    15         {
    16             printf("%c",str[n*i+j]);
    17         }
    18     }
    19     printf("
    ");
    20 }
    21 int main()
    22 {
    23     while(scanf("%d",&n),n)
    24     {
    25         scanf("%s",str);
    26         memset(ch,0,sizeof(ch));
    27         cnt=strlen(str)/n;
    28         for(int i=1;i<cnt;i+=2)
    29         {
    30             reverse(str+i*n,str+(i+1)*n);
    31         }
    32         output();
    33     }
    34     return 0;
    35 }
    View Code
  • 相关阅读:
    php获取文件后缀名格式
    猴子分桃问题2
    猴子吃桃问题1
    判断字符串中字母出现的次数用分割法
    成绩表
    二维数组所有元素求和输出
    冒泡排序
    1.8作业
    1.8
    1.6
  • 原文地址:https://www.cnblogs.com/cton/p/3436527.html
Copyright © 2011-2022 走看看