Compare commits
No commits in common. "ee576351d9feed23ca03eb693a2f0b68fa366ecb" and "71ea2b0d215b8243408058d3d8855e35663863ec" have entirely different histories.
ee576351d9
...
71ea2b0d21
6
push.bat
6
push.bat
@ -1,4 +1,4 @@
|
|||||||
git pull
|
git pull
|
||||||
git add -A
|
git add -A
|
||||||
git commit -m "Auto commit"
|
git commit -m "Auto commit"
|
||||||
git push
|
git push origin main
|
@ -1,77 +0,0 @@
|
|||||||
/*----------------------------------------------------------------------
|
|
||||||
【程序设计】
|
|
||||||
------------------------------------------------------------------------
|
|
||||||
输入一个字符串,由括号(英文括号)、数字和大写字母组成,字符串中形如(2A),表示2个连续的A即’AA’,字符串中形如(4AB),表示4个连续的AB,括号无嵌套.请对其解码得到原始字符串!
|
|
||||||
示例1:
|
|
||||||
输入字符串:(5A)
|
|
||||||
解码后字符串:AAAAA
|
|
||||||
|
|
||||||
示例2:
|
|
||||||
输入字符串:(3AC)
|
|
||||||
解码后字符串:ACACAC
|
|
||||||
|
|
||||||
示例3:
|
|
||||||
输入字符串:(3C)(4AB)
|
|
||||||
解码后字符串:CCCABABABAB
|
|
||||||
|
|
||||||
|
|
||||||
(不符合要求格式的字符串可以忽略不做处理)
|
|
||||||
------------------------------------------------------------------------
|
|
||||||
注意:部分源程序给出如下。请勿改动主函数main或其它函数中给出的内容,仅在
|
|
||||||
Program-End之间填入若干语句。不要删除标志否则不得分。
|
|
||||||
----------------------------------------------------------------------*/
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
|
|
||||||
int parseNumber(const char *str, int *index) {
|
|
||||||
int num = 0;
|
|
||||||
while (str[*index] >= '0' && str[*index] <= '9') {
|
|
||||||
num = num * 10 + (str[*index] - '0');
|
|
||||||
(*index)++;
|
|
||||||
}
|
|
||||||
return num;
|
|
||||||
}
|
|
||||||
|
|
||||||
void decodeString(char *s, char *out) {
|
|
||||||
char *p_read = s;
|
|
||||||
char *p_write = out;
|
|
||||||
char buf[64] = {0};
|
|
||||||
int digit_len = 0;
|
|
||||||
int repeats = 0;
|
|
||||||
while (*p_read){
|
|
||||||
/**********Program**********/
|
|
||||||
if(*p_read == '('){//找到左括号 //(3AC)
|
|
||||||
digit_len = 0;//字符需要打印个个数
|
|
||||||
digit_len = parseNumber(++p_read, &digit_len);//取出数字部分
|
|
||||||
while(*p_read >= '0' && *p_read <= '9'){/
|
|
||||||
p_read++;
|
|
||||||
}
|
|
||||||
repeats = 0;
|
|
||||||
while(*p_read != ')'){
|
|
||||||
buf[repeats++]=*p_read++;
|
|
||||||
|
|
||||||
}
|
|
||||||
buf[repeats]='\0';
|
|
||||||
|
|
||||||
for(repeats=0;repeats<digit_len;repeats++){
|
|
||||||
out = strcat(out, buf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
p_read++;
|
|
||||||
/********** End **********/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int main() {
|
|
||||||
char s[32] = {0};
|
|
||||||
char result[512] = {0};
|
|
||||||
|
|
||||||
printf("输入字符串s:");
|
|
||||||
scanf("%s", s);
|
|
||||||
decodeString(s, result);
|
|
||||||
printf("解码后字符串:%s", result);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user