CSES - Datatähti 2024 alku - Results
Submission details
Task:Monistus
Sender:maweiyin24562
Submission time:2023-11-03 17:06:53 +0200
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'bool isClear()':
input/code.cpp:10:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |         for(int i=0;i<str.size();i++){
      |                     ~^~~~~~~~~~~
input/code.cpp: In function 'std::string dfs(std::string)':
input/code.cpp:23:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         for(int i=0;i<s.size();i++){//O(n)
      |                     ~^~~~~~~~~
input/code.cpp:26:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |                         if(i+m>=s.size())
      |                            ~~~^~~~~~~~~~
input/code.cpp:30:35: error: expected ';' before '...

Code

#include<bits/stdc++.h>
using namespace std;
string str;

bool isDigit(char c){
	return c>='0'&&c<='9';
}

bool isClear(){
	for(int i=0;i<str.size();i++){
		if(isDigit(str[i]))return false;
	}
	return true;
}

bool vst=false;

string dfs(string s){
	if(s.size()<=1){
		return s;
	}
	string result="";
	for(int i=0;i<s.size();i++){//O(n)
		if(isDigit(s[i])&&!vst){
			int m=s[i]-'0';
			if(i+m>=s.size())
				result+=s[i];
			else
				result+=dfs(s.substr(i+1,m));
			vst=true;s
		}
		else{
			result+=s[i];
		}
	}
	return result;
}

int main(){
	cin>>str;
	
	while(!isClear()){//O(n)
		vst=false;
		str=dfs(str);
	}
	
	cout<<str<<endl;
	return 0;
}