AutoSkill C Election Vote Counter with Dynamic Alignment
A C program to read candidate names and votes from a file, calculate statistics (total, valid, invalid votes), determine winners, and print results with dynamically aligned columns based on name length.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8_GLM4.7/c-election-vote-counter-with-dynamic-alignment" ~/.claude/skills/ecnu-icalk-autoskill-c-election-vote-counter-with-dynamic-alignment && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8_GLM4.7/c-election-vote-counter-with-dynamic-alignment/SKILL.mdsource content
C Election Vote Counter with Dynamic Alignment
A C program to read candidate names and votes from a file, calculate statistics (total, valid, invalid votes), determine winners, and print results with dynamically aligned columns based on name length.
Prompt
Role & Objective
You are a C programmer tasked with processing an election results file. The input file contains a list of candidate names followed by a list of integer votes. You must read this data, calculate statistics, and write a formatted report to an output file.
Operational Rules & Constraints
-
Input Parsing:
- Read candidate names from the input file. Stop reading names when you encounter a digit or the vote section begins.
- Read the remaining integers as votes.
-
Vote Validation:
- A vote is valid if it is an integer between 1 and the total number of candidates.
- Count total votes, valid votes, and invalid votes.
-
Output Formatting:
- Write the results to a specified output file (e.g., "resultats.txt").
- Invalid Votes: Print "Vote invalide : <vote_value>" for each invalid vote encountered.
- Statistics: Print the following lines:
- "Nombre d'électeurs : <total_votes>"
- "Nombre de votes valides : <valid_votes>"
- "Nombre de votes annules : <invalid_votes>"
- Score Table: Print a header "Candidat score".
- Dynamic Alignment: Calculate the maximum length of all candidate names. When printing each candidate's name and score, pad the name with spaces so that the scores align vertically in a column. The padding should be based on the difference between the current name's length and the maximum name length.
- Winners: Print "Les gagnants:" followed by the names of all candidates who have the maximum score.
Communication & Style Preferences
- Provide the full C code.
- Use clear variable names.
- Ensure the code compiles and runs correctly.
Triggers
- count votes in C
- election results program
- align text columns in C
- process votes.txt
- calculate election winners