复习
字符判断
inlcude <cctype>
isupper(c) 是否为大写
islower(c) 是否为小写
isdigit(c) 是否为数字
isalpha(c) 是否为字母
isalnum(c) 是否为字母或数字
tolower() 大写字母转换为小写字母
toupper() 小写字母转换为大写字母
类似于字符串中整理数字的办法(ssre56sdf8)这种,找出里面的数字
int count = 0;
while(){
if(isdigit(string[i]){
count = count * 10 + string[i] - '0';
}
}
问题:
to_string 用不了,头文件也加了,不知道为什么
19分代码,第三点不知道哪里错了,也找不到哪里错了,,,
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <cctype>
#include <vector>
#include <cmath>
using namespace std;
char key;
int l;
string in,out;
string a;
void yasuo(){
getchar();
getline(cin,in);
l = in.length();
char com = ' ';
int num = 1;
for(int i=0; i<l+1; i++){
if(in[i] == com){
num = num + 1;
}
else {
if(i != 0){
if(num != 1){
cout << num << com;
}
else{
cout << com;
}
}
com = in[i];
num = 1;
}
}
cout << out << endl;
}
void jieya(){
getchar();
getline(cin,in);
l = in.length();
int wei = -1;
int flag = 0;
int num = 0;
vector<int> cun(0);
for(int i=0; i<l+1; i++){
if(isdigit(in[i])){
int c = in[i] - '0';
cun.push_back(c);
wei = wei + 1;
flag = 1;
}
else{
if(flag){
int ll = cun.size();
for(int k=0; k<ll; k++){
num += cun[k] * pow(10,wei);
wei = wei-1;
}
for(int j=0; j<num; j++)
cout << in[i];
flag = 0;
num = 0;
wei = -1;
cun.clear();
}
else cout << in[i];
}
}
}
int main(){
cin >> key;
if(key == 'C') yasuo();
else jieya();
return 0;
}
迷茫,,重写了解压部分还是不对,,难道是错在了压缩部分?
不深究了,,可能一些小点没办法,,