File tree Expand file tree Collapse file tree 3 files changed +103
-0
lines changed
solution/3400-3499/3484.Design Spreadsheet Expand file tree Collapse file tree 3 files changed +103
-0
lines changed Original file line number Diff line number Diff line change @@ -312,6 +312,42 @@ impl Spreadsheet {
312312}
313313```
314314
315+ #### C#
316+
317+ ``` cs
318+ public class Spreadsheet {
319+ private Dictionary <string , int > d = new Dictionary <string , int >();
320+
321+ public Spreadsheet (int rows ) {
322+ }
323+
324+ public void SetCell (string cell , int value ) {
325+ d [cell ] = value ;
326+ }
327+
328+ public void ResetCell (string cell ) {
329+ d .Remove (cell );
330+ }
331+
332+ public int GetValue (string formula ) {
333+ int ans = 0 ;
334+ foreach (string cell in formula .Substring (1 ).Split ('+' )) {
335+ ans += char .IsDigit (cell [0 ]) ? int .Parse (cell )
336+ : (d .ContainsKey (cell ) ? d [cell ] : 0 );
337+ }
338+ return ans ;
339+ }
340+ }
341+
342+ /**
343+ * Your Spreadsheet object will be instantiated and called as such:
344+ * Spreadsheet obj = new Spreadsheet(rows);
345+ * obj.SetCell(cell,value);
346+ * obj.ResetCell(cell);
347+ * int param_3 = obj.GetValue(formula);
348+ */
349+ ```
350+
315351<!-- tabs:end -->
316352
317353<!-- solution:end -->
Original file line number Diff line number Diff line change @@ -310,6 +310,42 @@ impl Spreadsheet {
310310}
311311```
312312
313+ #### C#
314+
315+ ``` cs
316+ public class Spreadsheet {
317+ private Dictionary <string , int > d = new Dictionary <string , int >();
318+
319+ public Spreadsheet (int rows ) {
320+ }
321+
322+ public void SetCell (string cell , int value ) {
323+ d [cell ] = value ;
324+ }
325+
326+ public void ResetCell (string cell ) {
327+ d .Remove (cell );
328+ }
329+
330+ public int GetValue (string formula ) {
331+ int ans = 0 ;
332+ foreach (string cell in formula .Substring (1 ).Split ('+' )) {
333+ ans += char .IsDigit (cell [0 ]) ? int .Parse (cell )
334+ : (d .ContainsKey (cell ) ? d [cell ] : 0 );
335+ }
336+ return ans ;
337+ }
338+ }
339+
340+ /**
341+ * Your Spreadsheet object will be instantiated and called as such:
342+ * Spreadsheet obj = new Spreadsheet(rows);
343+ * obj.SetCell(cell,value);
344+ * obj.ResetCell(cell);
345+ * int param_3 = obj.GetValue(formula);
346+ */
347+ ```
348+
313349<!-- tabs:end -->
314350
315351<!-- solution:end -->
Original file line number Diff line number Diff line change 1+ public class Spreadsheet {
2+ private Dictionary < string , int > d = new Dictionary < string , int > ( ) ;
3+
4+ public Spreadsheet ( int rows ) {
5+ }
6+
7+ public void SetCell ( string cell , int value ) {
8+ d [ cell ] = value ;
9+ }
10+
11+ public void ResetCell ( string cell ) {
12+ d . Remove ( cell ) ;
13+ }
14+
15+ public int GetValue ( string formula ) {
16+ int ans = 0 ;
17+ foreach ( string cell in formula . Substring ( 1 ) . Split ( '+' ) ) {
18+ ans += char . IsDigit ( cell [ 0 ] ) ? int . Parse ( cell )
19+ : ( d . ContainsKey ( cell ) ? d [ cell ] : 0 ) ;
20+ }
21+ return ans ;
22+ }
23+ }
24+
25+ /**
26+ * Your Spreadsheet object will be instantiated and called as such:
27+ * Spreadsheet obj = new Spreadsheet(rows);
28+ * obj.SetCell(cell,value);
29+ * obj.ResetCell(cell);
30+ * int param_3 = obj.GetValue(formula);
31+ */
You can’t perform that action at this time.
0 commit comments