zoukankan      html  css  js  c++  java
  • 杭电oj 2719

      Tips:本程序没有什么难度,只要按照逻辑进行替换即可,需要注意的是,由于输入串中含有空格符号,所以不能使用scanf("%s",ch);来读取一串,可以使用gets()函数读取一行字符。

     1 #include<stdio.h>
     2 #include<string.h>
     3 int main()
     4 {
     5     char ch[80];
     6     while(gets(ch))//不能使用sacnf("%s,ch),因为遇见空格就会结束读入
     7     {
     8         if(*ch == '#')
     9         {
    10             return 0;
    11         }
    12         char temp[240];
    13         int j=0;
    14         for(int i=0; i<strlen(ch);i++)
    15         {
    16             if(ch[i] == ' ')
    17             {
    18                 temp[j++] = '%';
    19                 temp[j++] = '2';
    20                 temp[j++] = '0';
    21             }else if(ch[i] == '!')
    22             {
    23                 temp[j++] = '%';
    24                 temp[j++] = '2';
    25                 temp[j++] = '1';
    26             }else if(ch[i] == '$')
    27             {
    28                 temp[j++] = '%';
    29                 temp[j++] = '2';
    30                 temp[j++] = '4';
    31             }else if(ch[i] == '%')
    32             {
    33                 temp[j++] = '%';
    34                 temp[j++] = '2';
    35                 temp[j++] = '5';
    36             }else  if(ch[i] == '(')
    37             {
    38                 temp[j++] = '%';
    39                 temp[j++] = '2';
    40                 temp[j++] = '8';
    41             }else if(ch[i] == ')')
    42             {
    43                 temp[j++] = '%';
    44                 temp[j++] = '2';
    45                 temp[j++] = '9';
    46             }else if(ch[i] == '*')
    47             {
    48                 temp[j++] = '%';
    49                 temp[j++] = '2';
    50                 temp[j++] = 'a';
    51             }else
    52             {
    53                 temp[j++] = ch[i];
    54             }
    55 
    56         }
    57 
    58         int i=0;
    59         while(i<j)
    60         {
    61             printf("%c",temp[i]);
    62             i++;
    63         }
    64 
    65         printf("
    ");
    66     }
    67     return 0;
    68 }
  • 相关阅读:
    Unity3D-ScrollRect 各参数的代码引用以及作用
    Unity3D-坐标转换笔记
    angularJS中XHR与promise
    angularJS中的事件
    angularJS中如何写服务
    angularJS中如何写自定义指令
    angularJS内置指令一览
    angularJS中如何写控制器
    理解angularJS中作用域$scope
    如何写angularJS模块
  • 原文地址:https://www.cnblogs.com/wujiyang/p/4534048.html
Copyright © 2011-2022 走看看