论全局变量与局部变量的区别

P1201 [USACO1.1] 贪婪的送礼者Greedy Gift Givers

@[逆流之时](/space/show?uid=144740) 是谁给你的勇气用 scanf 读入 string? QwQ
by 龙之吻—水货 @ 2019-04-15 17:41:23


(不过这样子似乎可以?
by 龙之吻—水货 @ 2019-04-15 17:42:03


@[逆流之时](/space/show?uid=144740) string 的 resize 只是把 string 空间重新分配,并没有把 string 初始化 QwQ
by 龙之吻—水货 @ 2019-04-15 17:43:46


@[逆流之时](/space/show?uid=144740) 初始化啊哥哥你用完都不清空...
by SkyLiYu @ 2019-04-15 17:46:03


```cpp #include<cstdio> #include<iostream> #include<string> std::string s; int main() { std::cin >> s; s.resize(20); std::cout << s << '\n'; s.resize(3); std::cout << s << '\n'; } ``` 输入 : ``` 12345 ``` 输出 : ``` 12345 123 ```
by 龙之吻—水货 @ 2019-04-15 17:46:06


@[逆流之时](/space/show?uid=144740) 我在你代码里加了个s.clear()分数瞬间[78](https://www.luogu.org/recordnew/show/18245159)了
by SkyLiYu @ 2019-04-15 17:47:55


~~然而我连原题都不知道是啥~~我就加了个s.clear()
by SkyLiYu @ 2019-04-15 17:48:56


是不是全局变量没清空..
by Hzao @ 2019-04-15 18:28:49


@[龙之吻—水货](/space/show?uid=49866) @[隔壁小邱](/space/show?uid=22539) @[Zaoaa](/space/show?uid=123147) 感谢%%%~~看来是我太菜了,字符串都没学好~~
by 逆流之时 @ 2019-04-15 19:13:56


考古
by xy_f @ 2020-03-10 10:00:22


| 下一页