【发布时间】:2022-12-01 14:04:01
【问题描述】:
im noob at prog, so i need help.
Need to make a string from each word in the array so that each letter copies itself as many times as the serial number in the word it has, and each new character must starts with uppercase;
Example:
"abcd" -> "A-Bb-Ccc-Dddd"
"RqaEzty" -> "R-Qq-Aaa-Eeee-Zzzzz-Tttttt-Yyyyyyy"
"cwAt" -> "C-Ww-Aaa-Tttt"
One of ways I tried to do it:
public static String Accum(string s)
{
string res;
for(int i = 0; i < s.Length; i++)
{
res += s[i].ToUpper() + s[i].ToLower().Repeat(i) + (i < s.Length - 1 ? "-": "");
}
return res;
}
- some errors, that I understand, but can't understand what to do with them(google didnt help so much):
error CS1501: No overload for method 'ToUpper' takes 0 arguments
error CS0165: Use of unassigned local variable 'res'
【问题讨论】:
-
"I tried a lot of wariations" - before all of us have to go through the same mistakes as you, please edit the question and include the code that you have tried. We do not provide code writing services here. The task sounds like a student assignment. You probably should know everything to solve it yourself.
-
im noob at prog<-- this does not automatically mean you are a noob at problem solving. Have you tried writing down / drawing up what you would expect would be the necessary steps to achieve the resulting string? That may help.
-
@Thomas Weller Made it, dont judge strictly :D
-
@Astrid E. Ok, thank you for the idea, idk why i havent thought about it xD
-
The idea of codewars is that you solve the puzzle yourself or you press the "surrender" button to see other people's code. It's discouraged to post solutions (or make other people post solutions as an answer).