UVa445
題敘
http://domen111.github.io/UVa-Easy-Viewer/?445
給一字串包含一迷宮的地圖資訊,求地圖的樣子
想法
依據題目對於地圖資訊的描述輸出相對應字元即可
數字部分可以另外用變數儲存,記得每次輸出完歸零
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
   |  #include<bits/stdc++.h> #define LL long long #define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); #define pii pair<int,int> using namespace std; char step; int cnt=0; int main(){ 	IOS 	while((step=cin.get())!=EOF){ 		if(step=='\n' || step=='!') 			cout<<"\n"; 		else if(step<='9' && step>='0'){ 			cnt+=(step-'0'); 		} 		else if((step<='Z' && step>='A') || step=='*'){ 			while(cnt){ 				cout<<step; 				cnt--; 			} 		} 		else if(step=='b'){ 			while(cnt){ 				cout<<' '; 				cnt--; 			} 		} 	} 	return 0; }
 
  | 
 
複雜度
$O(len(s))$