如何做问题的cc程序 [英] How to do cc programme of the question

查看:68
本文介绍了如何做问题的cc程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您是数据字符串的编码形式,如下所示:连续

出现的字母(最多9个)由字母
$表示b $ b后跟出现次数。



例如,字符串



a9a3b2c4de



代表字符串



aaaaaaaaaaaabbccccdc



- 也就是说,连续12次出现a,然后是2 bs,然后是

4 cs,然后是广告,最后是c



给定编码形式,你必须输出数据字符串。



输入

-----

字符串的编码形式,按照以下规则制作。

1.如果一个字符只出现一次,那么在编码的字符串中,它会显示为
这样的(例如,上面字符串中的'd'。)

2.如果字符的连续出现次数是2到9之间的
,那么它是代表因为角色跟随

的出现次数(例如aaaab表示为a4b)。

3.如果一个角色的连续出现次数比
大,那么按照规则2组出现9次。迭代
$的集合b $ b对剩余字符串进行规则。



输出

------

原文字符串,仅包含

编码作为输入的字符。



我尝试过: < br $> b $ b

You are the encoded form of a data string as follows: consecutive
occurrences of a letter (up to 9) are represented by the letter
followed by the number of occurrences.

For example, the string

a9a3b2c4de

stands for the string

aaaaaaaaaaaabbccccdc

- that is, 12 consecutive occurrences of a, followed by 2 bs, and then
4 cs, followed by a d and finally c

Given an encoded form, you have to output the data string.

Input
-----
The encoded form of the string, made as per the following rules.
1. If a character occurs only once, then in the encoded string, it
appears as such (for example, 'd' in the above string.)
2. If the number of consecutive occurrences of the character is
between 2 and 9, then it is represented as the character followed
by the number of occurrences (e.g. aaaab is represented as a4b).
3. If the number of consecutive occurrences of a character is greater
than 9, then group 9 occurrences as per rule 2. Iterate the set of
rules on the remaining string.

Output
------
The original string, consisting only of characters whose
encoding was given as input.

What I have tried:

#include<stdio.h>
 
int main() {
   char str[20], ch;
   int count = 0, i;
 
   printf("\nEnter a string : ");
   scanf("%s", &str);
 
   printf("\nEnter the character to be searched : ");
   scanf("%c", &ch);
 
   for (i = 0; str[i] != '\0'; i++) {
      if (str[i] == ch)
         count++;
   }
 
   if (count == 0)
      printf("\nCharacter '%c'is not present", ch);
   else
      printf("\nOccurence of character '%c' : %d", ch, count);
 
   return (0);
}

推荐答案

再次阅读你的作业问题。

你需要读一个字符串然后将它作为一对字符处理。

第一个字符是要重复的字符,第二个字符是重复它的时间(N)。



所有你需要做的就是打印炭黑N次,然后转移到下一对。



但这是你的功课,所以我我不给你任何密码!
Read your homework question again.
You need to read in a string, and then process it as pairs of characters.
The first character is the char to repeat, the second is the number of time to repeat it (N).

All you have to do is print the char N times, then move onto the next pair.

But this is your homework, so I'll give you no code!


plz help..我错了吗?



plz help..where am i wrong?

#include<stdio.h>
int main()
{
int i,n,s;
char a[100];
scanf("%d",&s);
for(i=0;i<s;i++)
{
scanf("%c",&a[i]);
}
for(i=0;i<s;i++)
{
if((a[i]>='a' && a[i]<='z')&&(a[i+1]>='a'&& a[i+1]<='z'))
{

printf("%c",a[i]);
}

else if((a[i]>='a' && a[i]<='z') &&(a[i+1]>=2 && a[i+1]<=9))
{

n=a[i+1];
while(n>0)
{
printf("%c",a[i]);
n=n-1;
}

}
}
if(a[s-1]>='a'&& a[s-1]<='z')
{
printf("%c",a[s-1]);
}
return 0;
}


根据要求

According to the requirements
a9a3b2c4de



应该扩展到


should expand to

aaaaaaaaaaaabbccccde



而不是


instead of

aaaaaaaaaaaabbccccdc





这就是说,扩展它真的很简单:

(错误处理,即错误的输入字符串格式,留作练习)



That said, expansion it is really a simple matter:
(error handling, i.e. incorrect input string format, left as exercise)

  1. 从编码字符串中读取下一个字符,如果没有下一个字符(到达字符串的末尾)则退出
  2. 如果读取的字符是字母,则将其添加到输出字符串并将其记录到变量中(例如 cur_char )返回步骤 1
  3. 读取的字符是一个数字,将其转换为相应的数字,比如 d 并将 cur_char d -times添加到输出字符串
  1. read next character from encoded string, if there isn't a next character (end of the string reached) then exit
  2. if the read character is a letter then add it to the output string and record it into a variable (say cur_char) go back to step 1.
  3. the read character is a digit, convert it into the corresponding number, say d and add cur_char d-times to the output string


这篇关于如何做问题的cc程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆