A - How to Type

Pirates have finished developing the typing software. He called Cathy to test his typing software. She is good at thinking. After testing for several days, she finds that if she types a string by some ways, she will type the key at least. But she has a bad habit that if the caps lock is on, she must turn off it, after she finishes typing. Now she wants to know the smallest times of typing the key to finish typing a string.

Input The first line is an integer t (t<=100), which is the number of test case in the input file. For each test case, there is only one string which consists of lowercase letter and upper case letter. The length of the string is at most 100. Output For each test case, you must output the smallest times of typing the key to finish typing this string. Sample Input
3
Pirates
HDUacm
HDUACM
Sample Output
8
8
8


        
  
Hint
The string “Pirates”, can type this way, Shift, p, i, r, a, t, e, s, the answer is 8.
The string “HDUacm”, can type this way, Caps lock, h, d, u, Caps lock, a, c, m, the answer is 8
The string "HDUACM", can type this way Caps lock h, d, u, a, c, m, Caps lock, the answer is 8

        
 
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <cstring>

using namespace std;

const int maxn = 1e4 + 10;
const int INF = 0x3f3f3f3f;
int t, n, m, ans = 0, sum;
int a[maxn][maxn], dpa[maxn], dpb[maxn];
int vis[maxn][maxn];
int dir[][2] = {{0, -1}, {0, -2}, {0, 1}, {0, 2}, {1, 0}, {2, 0}, {-1, 0}, {-2, 0} };
int main() {
    scanf("%d", &t);
    for(int i = 1; i <= t; i++) {
        char s[105];
        scanf("%s", s + 1);
        int len = strlen(s + 1) + 1;
        dpa[0] = 0; // Caps off
        dpb[0] = 1; // Caps on
        for(int j = 1; j < len; j++) {
            if(s[j] >= 'a' && s[j] <= 'z') {
                        // sc             // turn off Caps + sc
                dpa[j] = min(dpa[j - 1] + 1, dpb[j - 1] + 2);
                        // sc + turn on Caps // shift + sc 
                dpb[j] = min(dpa[j - 1] + 2, dpb[j - 1] + 2);
            } else {
                        // shift + sc       // sc + turn off Caps
                dpa[j] = min(dpa[j - 1] + 2, dpb[j - 1] + 2);
                        // turn on Caps + sc // sc
                dpb[j] = min(dpa[j - 1] + 2, dpb[j - 1] + 1);
            }
        }
        printf("%d\n", min(dpb[len - 1] + 1, dpa[len - 1]));
    }
    return 0;
}


<think>Hmm, the user is asking about the error "conversion to non-scalar type requested" in Chinese context. This is clearly a programming-related question, likely from someone working with C/C++ given how specific the error message is. First, I recall this error typically occurs when trying to assign a struct or array to a scalar variable type like int or float. The user might be frustrated since this breaks compilation. Looking deeper, they probably encountered this while passing incompatible types between functions or during assignment. Maybe they're mixing pointers and values? The core issue is type system enforcement - C compilers reject mismatched aggregate-to-scalar conversions. I should explain the technical cause clearly but simply: emphasize it's about assigning complex types to simple variables. The solution involves consistent typing and pointers where needed. Since they requested Chinese response, I'll maintain technical accuracy while using simple terms like "複合數據類型" (complex data types) and "基礎類型" (basic types). For the required follow-up questions, I'll design probes that address common related pitfalls: struct initialization syntax, pointer usage variations, and array decay - all frequent trouble spots after this error. These should help the user self-diagnose next time. The example format shows I must include code blocks when relevant, but here a conceptual explanation suffices since the error manifests differently across contexts. Still, I'll mention function calls and assignments as prime examples. Noticing the user didn't provide code - wise choice since generic advice fits better here. They seem experienced enough to recognize the error term but need clarification on its meaning. No emotional cues in query, so keeping response professionally neutral. </think>"conversion to non-scalar type requested" 是 C/C++ 編譯錯誤,通常發生在嘗試將**複合數據類型**(如結構體、陣列)賦值或轉換為**基礎類型**(如 `int`, `float`)時。以下是常見原因和解決方案: ### 常見原因及解決方法: 1. **結構體/陣列賦值給標量變量** ```c struct Point { int x, y; } p; int a = p; // 錯誤:嘗試將 struct 轉換為 int ``` **修正**:使用成員變量 `int a = p.x;` 2. **函數返回值類型不匹配** ```c struct Data getData(); int num = getData(); // 錯誤:函數返回 struct 但試圖轉為 int ``` **修正**:修改接收類型 `struct Data d = getData();` 3. **誤用指針和值** ```c int arr[3] = {1,2,3}; int val = arr; // 錯誤:陣列名退化成指針,無法轉為 int ``` **修正**:使用具體元素 `int val = arr[0];` 4. **類型強制轉換錯誤** ```c void* ptr = malloc(sizeof(int)); int num = (int)ptr; // 錯誤:指針不能直接轉為 int(需用 intptr_t) ``` **修正**:使用 `intptr_t num = (intptr_t)ptr;` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值